Why are posts from custom post type not displayed in “category” archive?

You need to hook into the query because the category archive page explicitly only includes the ‘post’ type and nothing else.

function namespace_add_custom_types( $query ) {
  if( (is_category() || is_tag()) && $query->is_archive() && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'post_type', array(
     'post', 'myposttime'
        ));
    }
}
add_action( 'pre_get_posts', 'namespace_add_custom_types' );

Modified from this article on CSS Tricks.

Leave a Comment