Make WordPress Core

Opened 14 years ago

Closed 11 years ago

#16465 closed defect (bug) (fixed)

Querying taxonomies can trigger notices

Reported by: hakre's profile hakre Owned by: markjaquith's profile markjaquith
Milestone: 3.6 Priority: normal
Severity: normal Version: 3.1
Component: Warnings/Notices Keywords: has-patch
Focuses: Cc:

Description

Taxonomy queries variables related to backwards-compatbile taxonomy queries like $cat_query (category) or $tag_query (post_tag) do notices because they expect to have a term available.

But that's not the case if those taxonomies are getting queried "advanced" regardless of a concrete term.

Related: #15007 / [15685]

The related feature is: Advanced multi-taxonomy WP_Query()s (#12891, #15752)

Attachments (2)

16465.patch (1.0 KB) - added by hakre 14 years ago.
16465.diff (1.6 KB) - added by wonderboymusic 12 years ago.

Download all attachments as: .zip

Change History (15)

@hakre
14 years ago

#1 @hakre
14 years ago

  • Version set to 3.1

#2 @hakre
14 years ago

More Info: Normally, custom taxonomy queries are merged with default values (WP_Tax_Query constructor). For those two here, this does not have influence for some reason.

I'm adding the custom taxonomy query for those two in hook pre_get_posts.

#3 follow-up: @scribu
14 years ago

  • Keywords reporter-feedback added

Please provide some steps to reproduce.

#4 in reply to: ↑ 3 @hakre
14 years ago

Replying to scribu:

Please provide some steps to reproduce.

Add the following code prior init and after add_filter has become available (e.g. must-use plugin), it's adding a tax_query to any query.

Then request homepage or feed.

add_filter('pre_get_posts', function(WP_query $query) {	
	$taxonomyQuery = array(
		'taxonomy' => 'category',
	    );
	isset($query->query_vars['tax_query']) 
	    || $query->query_vars['tax_query'] = array()
            ;
	$query->query_vars['tax_query'][] = $taxonomyQuery;
});

Default values should normally take care of the other array entries I've not used here.

#5 follow-up: @scribu
14 years ago

  • Keywords close added; reporter-feedback removed

If you also add a 'terms' key, the notices go away.

Since we don't support taxonomy indexes, this ticket is invalid.

#6 in reply to: ↑ 5 ; follow-up: @hakre
14 years ago

Replying to scribu:

If you also add a 'terms' key, the notices go away.

That's what I thought as first as well.

But even with 'terms' = array(), you get the notices.

And that's the default value I would expect to see in there when instantiating WP_Tax_Query as done in WP_Query->parse_tax_query().

Since we don't support taxonomy indexes, this ticket is invalid.

Actually taxonomy indexes are far away from that, I only start to test against default values here.

#7 in reply to: ↑ 6 ; follow-up: @scribu
14 years ago

Replying to hakre:

But even with 'terms' = array(), you get the notices.

That's equivalent to not setting it at all. The idea is that you're not passing any terms. The notices go away if you set 'terms' => array('foo').

You also have 'taxonomy' => '' as a default, but you don't expect that to work.

#8 in reply to: ↑ 7 @hakre
14 years ago

Replying to scribu:

I expect it to work in the meaning of not querying any data while not giving notices.

The first part already works, but the part about the notices still has problems.

#9 @markjaquith
14 years ago

  • Keywords close removed
  • Milestone changed from Awaiting Review to Future Release

Still, it's good to minimize cryptic notices as much as possible. As long as the changes are small and non-functional, we should welcome notice reductions.

#10 @hakre
14 years ago

Related: #16703

#11 @wonderboymusic
12 years ago

  • Milestone changed from Future Release to 3.6

Refreshed / cleaned

#12 @DrewAPicture
12 years ago

16465.diff clears the notices for me.

#13 @markjaquith
11 years ago

  • Owner set to markjaquith
  • Resolution set to fixed
  • Status changed from new to closed

In 24456:

Squash some PHP notices in taxonomy queries.

props hakre, wonderboymusic. fixes #16465.

Note: See TracTickets for help on using tickets.