DEV Community

Prabhat Jani
Prabhat Jani

Posted on

How To Show Custom Post Types in Category Archive Page

By default WordPress custom post types do not appear in a category or tag archive page, to change this behaviour and display the custom post type you can add this filter/function to your themes functions.php file.

function examcraze_show_cpt_archives( $query ) {
 if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
 $query->set( 'post_type', array(
 'post', 'nav_menu_item', 'custom-post-type-name-here'
 return $query;
add_filter( 'pre_get_posts', 'examcraze_show_cpt_archives' );
Enter fullscreen mode Exit fullscreen mode

Just add your custom post type name to suit, or to add more than one just comma separate the names.

Discussion (0)