From 322919eb1ca8a0fa0b6f4f042b2b27da75f9f114 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: https://develop.svn.wordpress.org/trunk@21855 602fd350-edb4-49c9-b593-d223f7449a82 --- 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;