Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#15752 closed defect (bug) (fixed)

Multiple taxonomy queries refinements

Reported by: scribu Owned by:
Milestone: 3.1 Priority: normal
Severity: minor Version:
Component: General Keywords:
Focuses: Cc:


Follow-up to #12891:

  • ommiting 'field' or 'operator' from a tax query causes notices
  • we use IN, even if we don't really support an array of taxonomies

Attachments (2)

15752.diff (3.4 KB) - added by scribu 9 years ago.
Introduce _set_tax_query_defaults()
WP_Tax_Query.diff (9.5 KB) - added by scribu 9 years ago.

Download all attachments as: .zip

Change History (29)

9 years ago

Introduce _set_tax_query_defaults()

#1 @scribu
9 years ago

  • Keywords has-patch added

#2 @demetris
9 years ago

Applied the patch and it works OK for my case. (Before the patch I was getting notices of undefined indexes if I did not define operator in a tax query.)

#3 @scribu
9 years ago

(In [16843]) Set tax query defaults earlier, for notice prevention and convenience. See #15752

#4 @scribu
9 years ago

(In [16844]) Proper check for tax query, which will never be empty, due to 'relation'. See #15752

#5 @scribu
9 years ago

r16844 just replaces this:

!$this->is_singular && !empty($this->tax_query)

with this:

$this->is_category || $this->is_tag || $this->is_tax

#6 @automattor
9 years ago

(In [16845]) False advertising is bad. See #15752

9 years ago

#7 @scribu
9 years ago

WP_Tax_Query.diff just wraps get_tax_sql(), _set_tax_query_defaults() and _transform_terms() into a class.

The main advantage is that the queries are separated from the 'relation' arg, making them easier to work with.

#8 @scribu
9 years ago

(In [16849]) Introduce WP_Tax_Query. Fix canonical redirects in the process. See #15752

#9 @scribu
9 years ago

(In [16850]) Correct relation var and PHP4 constructor. See #15752

#10 @scribu
9 years ago

(In [16851]) Always have a WP_Tax_Query instance, to prevent notices. See #15752

#11 @scribu
9 years ago

I'll start adding inline docs tomorrow, if there are no more problems.

#12 @ocean90
9 years ago

Still getting:
Notice: Trying to get property of non-object in /wp-includes/query.php on line 2657

Warning: Invalid argument supplied for foreach() in /wp-includes/functions.php on line 3064

#13 follow-up: @scribu
9 years ago

  • Keywords has-patch removed

Steps to reproduce?

#14 in reply to: ↑ 13 @ocean90
9 years ago

Replying to scribu:

Steps to reproduce?

On each admin page after the footer.

#15 @scribu
9 years ago

Confirmed. Working on a fix.

#16 @scribu
9 years ago

(In [16853]) Fix notice in get_queried_object(). See #15752

#17 @scribu
9 years ago

Should probably make an alias for $this->is_category || $this->is_tag || $this->is_tax.

#18 @scribu
9 years ago

(In [16854]) Inline docs for WP_Tax_Query. See #15752

#19 @scribu
9 years ago

Currently, a plugin hooking into 'pre_get_posts' doesn't have access to the tax query object, so it would have to call parse_tax_query() on it's own.

#20 @scribu
9 years ago

(In [16886]) Set $wp_query->tax_query earlier. See #15752

#21 @scribu
9 years ago

(In [16894]) Always set groupby when a tax query is involved. See #15752

#22 @tott
9 years ago

  • Cc tott added

r16853 seems to introduce trouble with custom permalink structures such as


In this cases the queried object refers to the term an not the post.

Changing the if condition to something like this seems to work.

if ( ( $this->is_category || $this->is_tag || $this->is_tax ) && ( ! $this->is_singular() && is_null( $this->post )  ) ) {

#23 @scribu
9 years ago

Can't reproduce using r16906.

#24 @ryan
9 years ago

Can't reproduce either.

#25 @ryan
9 years ago

Did rewrite rules change, perhaps? Mine flushed when I changed to the new structure, so I can't tell.

#26 @ryan
9 years ago

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

Latest trunk fixes this for wp.com.

#27 @hakre
9 years ago

Related: #16464

Note: See TracTickets for help on using tickets.