Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#39354 closed defect (bug) (fixed)

Unable to filter term query args using `pre_get_terms` action

Reported by: jfarthing84's profile jfarthing84 Owned by: boonebgorges's profile boonebgorges
Milestone: 4.8 Priority: normal
Severity: normal Version: 4.7
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description

Thus making the action practically useless. But fear not, there is a simple remedy. In fact, the same remedy is used in WP_Query::get_posts! Use a reference within WP_Term_Query::get_terms to access the query vars locally:

$args = &$this->query_vars;

Attachments (1)

39354.patch (487 bytes) - added by jfarthing84 7 years ago.

Download all attachments as: .zip

Change History (7)

@jfarthing84
7 years ago

#1 @jfarthing84
7 years ago

  • Keywords has-patch added

#2 @boonebgorges
7 years ago

  • Component changed from General to Taxonomy
  • Milestone changed from Awaiting Review to 4.8
  • Owner set to boonebgorges
  • Status changed from new to reviewing

Good call. Thanks for the patch, @jfarthing84.

#3 @boonebgorges
7 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 39625:

Taxonomy: Ensure that mods to query vars in pre_term_query callbacks have an effect.

Previously, it was possible to modify the query_vars array, but
the changes would be ignored after pre_term_query had finished
running.

Props jfarthing84.
Fixes #39354.

#4 @boonebgorges
7 years ago

#39457 was marked as a duplicate.

#5 @littler.chicken
7 years ago

A note, changeset 39625 breaks code which works in 4.7 and earlier:

	$taxonomies = get_taxonomies();
	$args       = array( 'orderby' => 'count', 'order' => 'DESC' );
	$terms      = wp_get_object_terms( get_the_ID(), $taxonomies, $args );

It may be that this code is faulty and deserves to break (properly using get_object_taxonomies() works), but I thought I would mention it, in case I'm not the only one affected.

#6 @boonebgorges
7 years ago

#40551 was marked as a duplicate.

Note: See TracTickets for help on using tickets.