WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 22 months ago

#16465 closed defect (bug) (fixed)

Querying taxonomies can trigger notices

Reported by: hakre Owned by: 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 4 years ago.
16465.diff (1.6 KB) - added by wonderboymusic 2 years ago.

Download all attachments as: .zip

Change History (15)

@hakre4 years ago

comment:1 @hakre4 years ago

  • Version set to 3.1

comment:2 @hakre4 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.

comment:3 follow-up: @scribu4 years ago

  • Keywords reporter-feedback added

Please provide some steps to reproduce.

comment:4 in reply to: ↑ 3 @hakre4 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.

comment:5 follow-up: @scribu4 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.

comment:6 in reply to: ↑ 5 ; follow-up: @hakre4 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.

comment:7 in reply to: ↑ 6 ; follow-up: @scribu4 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.

comment:8 in reply to: ↑ 7 @hakre4 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.

comment:9 @markjaquith4 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.

comment:10 @hakre4 years ago

Related: #16703

@wonderboymusic2 years ago

comment:11 @wonderboymusic2 years ago

  • Milestone changed from Future Release to 3.6

Refreshed / cleaned

comment:12 @DrewAPicture2 years ago

16465.diff clears the notices for me.

comment:13 @markjaquith22 months 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.