Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#24204 closed defect (bug) (fixed)

Tax query forces multiple post type treatment due to array check

Reported by: nacin Owned by: nacin
Milestone: 3.6 Priority: normal
Severity: normal Version:
Component: Query Keywords:
Focuses: Cc:


In WP_Query, if you have more than one post type in the query, things get much more complicated, because we can't do generic permissions checks in SQL. Prime example would be read_private_posts. I spotted the bug here because I was not able to see private posts by others in a widget produced with the help of a tax query.

Sometimes what happens instead is $post_type is set to either 'multiple_post_type' or 'any' to deliberately throw off cap checks. These should probably be more special and handled in a better way. That is not the bug I am reporting, though.

When is_tax, we loop through the taxonomies to extract the associated post types, rather than specifying 'any' as we had done prior to #21290. $post_type ends up always being an array here, even if there's only one post type found.

Later on, when deciding if we are dealing with multiple post types, we only check is_array() — an array with one element is not properly treated as a single post type query.

We should adjust both cases. Let's let $post_type be scalar if that's all we found in the is_tax branch, but let's also treat an array( $one_post_type ) as exactly one post type.

Change History (1)

#1 @nacin
8 years ago

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

In 24115:

WP_Query: If the post_type QV is an array with only one element, don't treat it as a multiple post type query.

If there is only one post type used by all taxonomies for a tax query, set the post type to the string.

fixes #24204.

Note: See TracTickets for help on using tickets.