[wp-trac] [WordPress Trac] #19471: Automatically support custom post types in category and tag archives
WordPress Trac
wp-trac at lists.automattic.com
Wed Dec 7 23:53:16 UTC 2011
#19471: Automatically support custom post types in category and tag archives
--------------------------+------------------------------
Reporter: chrisbliss18 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 3.0
Severity: normal | Resolution:
Keywords: has-patch |
--------------------------+------------------------------
Comment (by chrisbliss18):
Replying to [comment:8 DrewAPicture]:
> I can confirm this problem in 3.2.1. We employed a similar filter to
accommodate a CPT on archives pages. We also fixed the 'breaking menus
problem', by adding `nav_menu_item` to the $post_type array...
That really only avoids the main issue. The primary problem is that some
queries should not be modified. Simply forcing nav_menu_item into every
query is not a proper solution.
I sent the following to the plugin author as a temporary fix until WP core
updates:
{{{
#!php
<?php
add_filter( 'pre_get_posts', 'sp_ev_filter_query_post_type' );
function sp_ev_filter_query_post_type( $query ) {
if ( $query->query_vars['suppress_filters'] || ( ! is_category() && !
is_tag() ) )
return $query;
$post_type = get_query_var( 'post_type' );
if ( 'any' == $post_type )
return $query;
if ( empty( $post_type ) ) {
$post_type = 'any';
}
else {
if ( ! is_array( $post_type ) )
$post_type = array( $post_type );
$post_type[] = 'external-videos';
}
$query->set( 'post_type', $post_type );
return $query;
}
?>
}}}
By no means is this rock-solid, but it's much better than what was there
before. It attempts to apply a fix similar to the one provided by this
patch.
Key changes are respecting the suppress_filters var, using the 'any'
post_type, bailing out when no modifications are needed, and adding to the
post_type list rather than replacing the current value or values.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/19471#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list