WordPress.org

Make WordPress Core

Changeset 21855


Ignore:
Timestamp:
09/15/12 19:44:51 (22 months ago)
Author:
nacin
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/query.php

    r21836 r21855  
    22212221        if ( $this->is_tax ) { 
    22222222            if ( empty($post_type) ) { 
    2223                 $post_type = 'any'; 
     2223                // Do a fully inclusive search for currently registered post types of queried taxonomies 
     2224                $post_type = array(); 
     2225                $taxonomies = wp_list_pluck( $this->tax_query->queries, 'taxonomy' ); 
     2226                foreach ( get_post_types( array( 'exclude_from_search' => false ) ) as $pt ) { 
     2227                    if ( array_intersect( $taxonomies, get_object_taxonomies( $pt ) ) ) 
     2228                        $post_type[] = $pt; 
     2229                } 
     2230                if ( ! $post_type ) 
     2231                    $post_type = 'any'; 
     2232 
    22242233                $post_status_join = true; 
    22252234            } elseif ( in_array('attachment', (array) $post_type) ) { 
Note: See TracChangeset for help on using the changeset viewer.