September 27, 2017
If your Custom Post Types are not showing up in your archive.php or category.php templates (even with ‘has_archive’ => true enabled within the register_post_type function), you may need to do some additional theme adjustments!
Use this function to display the archives.
Original:
function wpa_cpt_tags( $query ) { if ( $query->is_tag() && $query->is_main_query() ) { $query->set( 'post_type', array( 'post', 'object' ) ); } } add_action( 'pre_get_posts', 'wpa_cpt_tags' );
Modified:
The comment on the source link describes a way to include all categories within the function, shown below.
function wpa_cpt_tags( $query ) { if ( $query->is_tag() || $query->is_category() && $query->is_main_query() ) { $query->set( 'post_type', array( 'post', 'custom_post_type' ) ); } } add_action( 'pre_get_posts', 'wpa_cpt_tags' );
Sourced here.