When working with custom post types you might want to include them in particular result sets such as tag pages or category pages.
All you need to do in order to achieve this is hooking a little function in the parse_query
action.
function query_my_post_types( &$query ) { // Do this for all category and tag pages, can be extended to is_search() or is_home() ... if ( is_category() || is_tag() ) { $post_type = $query->get( 'post_type' ); // ... if no post_type was defined in query then set the defaults ... if ( empty( $post_type ) ) { $query->set( 'post_type', array( 'post', 'custom-post-type1', // your custom post type 'custom-post-type2', // an other custom post type ) ); } } } add_action( 'parse_query', 'query_my_post_types' );
No comments yet... Be the first to leave a reply!