Support » Developing with WordPress » Custom Post Type category page not displaying CPT categories

  • I have setup a CPT “portfolio”:

    function register_cpt_portfolio() {
    	$labels = array( 
    		'name' 					=> _x( 'Portfolio', 'portfolio' ),
    		'singular_name' 		=> _x( 'Portfolio', 'portfolio' ),
    		'add_new' 				=> _x( 'Add New', 'portfolio' ),
    		'add_new_item' 			=> _x( 'Add New Portfolio', 'portfolio' ),
    		'edit_item' 			=> _x( 'Edit Portfolio', 'portfolio' ),
    		'new_item' 				=> _x( 'New Portfolio', 'portfolio' ),
    		'view_item' 			=> _x( 'View Portfolio', 'portfolio' ),
    		'search_items' 			=> _x( 'Search Portfolio', 'portfolio' ),
    		'not_found' 			=> _x( 'No portfolio items found', 'portfolio' ),
    		'not_found_in_trash' 	=> _x( 'No portfolio items found in Trash', 'portfolio' ),
    		'parent_item_colon'		=> _x( 'Parent portfolio:', 'portfolio' ),
    		'menu_name' 			=> _x( 'Portfolio', 'portfolio' )
    	$args = array( 
    		'can_export'			=> true,
    		'capability_type'		=> 'post',
    		'description'			=> 'Portfolio items of previous work',
    		'exclude_from_search'	=> false,
    		'has_archive'			=> true,
    		'hierarchical'			=> false,
    		'labels' 				=> $labels,
    		'menu_icon'				=> 'dashicons-portfolio',
    		'public'				=> true,
    		'publicly_queryable'	=> true,
    		'query_var'				=> true,
    		'rewrite'				=> true,
    		'show_in_menu'			=> true,
    		'show_in_nav_menus'		=> true,
    		'show_in_rest' 			=> true,
    		'show_ui'				=> true,
    		'supports'				=> array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'custom-fields', 'revisions' ),
    		'taxonomies' 			=> array('category', 'post_tag')
    	register_post_type( 'portfolio', $args );
    add_action( 'init', 'register_cpt_portfolio' );

    I have created an archive page: archive-portfolio.php

    On the archive-portfolio.php page, I am displaying the categories for each portfolio post_type:

    <?= get_the_category_list( esc_html__( ', ', 'quark' ) ) ?>

    When I click the link to a category, I end up at:


    This page shows the default ‘post’ posts category and the posts within.

    1. What is the default custom post type category URL
    2. How to I get the correct URL using ()

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    The category URL is the same as it is for posts. The problem is WP doesn’t add your CPT to the query criteria, you need to do it yourself through the “pre_get_posts” action.

    Assuming your category term is “editing”, /category/editing/ is correct, you just need to correct the query. If you don’t want posts and portfolios to be together in a single category query, and you still need post category functionality alone, you need a different taxonomy for your portfolio posts. It can still be labeled as “Category”, but its slug needs to be unique.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.