wp_list_categories and custom post types

By default, category archives only show posts of the default ‘post’ type.
The below code should get it working how you want. —via CSS Tricks

function namespace_add_custom_types( $query ) {
    if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
        $query->set( 'post_type', array(
            'post', 'your-custom-post-type-here'
        ));
        return $query;
    }
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );

Leave a Comment

tech