Custom Taxonomy with Custom Post Type Finds No Posts

I don’t know how or why, but this code below solved by issue. Seems to me like I shouldn’t need it, but apparently I do.

add_filter('pre_get_posts', array(&$this, 'modify_pre_query_request'));
public function modify_pre_query_request($query){
    if ($query->is_main_query()){
        if ($query->is_tax){
            $post_type = get_query_var('post_type');
            if (!$post_type){
                $post_type = array( 'post', 'YOUR POST TYPE' );
                $query->set('post_type', $post_type);
            }
        }
    }
}

Keep in mind that the above code is for an object-oriented theme, if you do not work on an object-oriented theme, use the following code instead:

add_filter('pre_get_posts', 'modify_pre_query_request');
function modify_pre_query_request($query){
    if ($query->is_main_query()){
        if ($query->is_tax){
            $post_type = get_query_var('post_type');
            if (!$post_type){
                $post_type = array( 'post', 'YOUR POST TYPE' );
                $query->set('post_type', $post_type);
            }
        }
    }
}

Thanks for all the help!

Leave a Comment