Opened 14 years ago
Closed 11 years 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.
The related feature is: Advanced multi-taxonomy WP_Query()s (#12891, #15752)
Attachments (2)
Change History (15)
#3
follow-up:
↓ 4
@
14 years ago
- Keywords reporter-feedback added
Please provide some steps to reproduce.
#4
in reply to:
↑ 3
@
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:
↓ 6
@
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:
↓ 7
@
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:
↓ 8
@
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
@
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
@
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.
#12
@
12 years ago
16465.diff clears the notices for me.
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.