How can I display an archive of only one category of my custom post type?

This is different from the question: How to display categories of my Custom Post Type?

I have a custom post type – podcasts. I have added the taxonomy “category” as I want my ‘podcasts’ to share the ‘category’ taxonomy with my posts. I have an archive page (archive-podcasts.php) that displays the podcasts at the url /podcasts/, but it shows all the categories. I would like to display my podcasts in a single category at a time, such as at

or even better:

Ideally it would use my existing archive-podcasts.php template.

Here’s my custom post type creation:

function podcast_post_type() {

// Set UI labels for Podcast post Type
    $labels = array(
       //redacted my labels because they aren't important here.

// Set other options for Podcast post Type

    $args = array(
        'label'               => __( 'podcasts', 'understrap' ),
        'description'         => __( 'Podcasts', 'understrap' ),
        'labels'              => $labels,
        // Features this CPT supports in Post Editor
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        // You can associate this CPT with a taxonomy or custom taxonomy. 
        'taxonomies'          => array(  'category' ),
        /* A hierarchical CPT is like Pages and can have
        * Parent and child items. A non-hierarchical CPT
        * is like Posts.
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'post',

    // Registering your Podcast post Type
    register_post_type( 'podcasts', $args );


The following code seemed promising but didn’t work:

add_action('init', 'category_cpt_rewrites');

function category_cpt_rewrites() {
    $custom_post_types = array('podcasts'); //some example post types
    foreach ( $custom_post_types as $post_type ) {
        $rule = '^' . $post_type . '/category/(.+?)/?$';
        $rewrite = 'index.php?post_type=' . $post_type . '&category_name=$matches[1]';

I actually kind of expected this would work automatically – that by adding the ‘category’ taxonomy to my post type,I thought WordPress would have a url where I could access my podcast categories.

I’ve lost a lot of time to this, and it seems like it should be simple – any help is appreciated!

Solutions Collecting From Web of "How can I display an archive of only one category of my custom post type?"

Try this and let us know if it works:

function custom_category_rewrite() {

     * Here you build an array containing the post type keys that you want
     * the rule to work for.
    $custom_post_types = array('podcast');

    foreach ( $custom_post_types as $post_type ) {
         * Adds rewrite rule which will rewrite sth like to
        add_rewrite_rule( "^$post_type/category/(.+)/?$", 'index.php?post_type=' . $post_type . '&category_name=$matches[1]', 'top' );



add_action( 'init', 'custom_category_rewrite' );

Put the code within your functions.php.

Pay attention to the comments along the snippet.

Try accessing something like to perform a test.