[wp-trac] [WordPress Trac] #21290: Post types continue to be selected after removal from custom taxonomy registration
WordPress Trac
noreply at wordpress.org
Tue Dec 18 07:02:20 UTC 2012
#21290: Post types continue to be selected after removal from custom taxonomy
registration
--------------------------+---------------------------
Reporter: jondavidjohn | Owner: jondavidjohn
Type: defect (bug) | Status: closed
Priority: normal | Milestone: 3.5
Component: Taxonomy | Version: 3.4.1
Severity: major | Resolution: fixed
Keywords: close |
--------------------------+---------------------------
Comment (by wonderboymusic):
I am not in love with the side effects of this. If you have a taxonomy in
mutiple blogs, there can be different post types assigned to the taxonomy
in each blog.
Site # 1
{{{
add_action( 'init', function () {
register_post_type( 'pizza', array( 'public' => true ) );
register_post_type( 'ice_cream', array( 'public' => true ) );
register_taxonomy( 'flavor', array( 'pizza', 'ice_cream' ) );
} );
add_action('pre_get_posts', function ( &$query ) {
if ( $query->is_main_query() ) {
$query->set( 'post_type', array( 'pizza', 'ice_cream' ) );
}
});
}}}
Site # 2
{{{
register_taxonomy( 'flavor', 'post' );
}}}
Default `WP_Query` with `post_type` set to `ice_cream` and `pizza` in
`pre_get_posts`:
{{{
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts
WHERE 1=1 AND wp_posts.post_type IN ('ice_cream', 'pizza')
AND (wp_posts.post_status = 'publish')
ORDER BY wp_posts.post_date DESC LIMIT 0, 10
}}}
Now let's `switch_to_blog` and do a `tax_query`:
{{{
switch_to_blog(2);
$query = new WP_Query( array(
'tax_query' => array(
array(
'taxonomy' => 'flavor',
'include_children' => false,
'field' => 'term_taxonomy_id',
'operator' => 'IN',
'terms' => array( 1 )
)
) ) );
}}}
Previously this would look for posts, but not anymore:
{{{
SELECT SQL_CALC_FOUND_ROWS wp_2_posts.ID
FROM wp_2_posts INNER JOIN wp_2_term_relationships
ON (wp_2_posts.ID = wp_2_term_relationships.object_id)
WHERE 1=1
AND ( wp_2_term_relationships.term_taxonomy_id IN (1) )
AND wp_2_posts.post_type IN ('pizza', 'ice_cream')
AND (wp_2_posts.post_status = 'publish')
GROUP BY wp_2_posts.ID ORDER BY wp_2_posts.post_date
}}}
I personally view tax_query as a filter on defaults. `post` should be the
assumption for `post_type`.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21290#comment:21>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list