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
This commit is contained in:
Andrew Nacin 2012-09-15 19:44:51 +00:00
parent 168d12a728
commit 322919eb1c
1 changed files with 10 additions and 1 deletions

View File

@ -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;