From 9ae3bf6fa69d532c8d96ff9f0b3a91cde0bf819b Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sat, 15 Sep 2012 19:44:51 +0000 Subject: [PATCH] When doing a taxonomy query, search against the currently registered post types of the queried taxonomies. Prevents posts of a type no longer assigned to a queried taxonomy from being returned. props jondavidjohn. fixes #21290. git-svn-id: http://core.svn.wordpress.org/trunk@21855 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index bb6c6e229b..272df00864 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -2220,7 +2220,16 @@ class WP_Query { if ( $this->is_tax ) { if ( empty($post_type) ) { - $post_type = 'any'; + // Do a fully inclusive search for currently registered post types of queried taxonomies + $post_type = array(); + $taxonomies = wp_list_pluck( $this->tax_query->queries, 'taxonomy' ); + foreach ( get_post_types( array( 'exclude_from_search' => false ) ) as $pt ) { + if ( array_intersect( $taxonomies, get_object_taxonomies( $pt ) ) ) + $post_type[] = $pt; + } + if ( ! $post_type ) + $post_type = 'any'; + $post_status_join = true; } elseif ( in_array('attachment', (array) $post_type) ) { $post_status_join = true;