I have created a custom post type (portfolio) and I'm using the built-in Category taxonomy with it. When I view the category archives page, only regular posts are showing under the category, my custom posts aren't there at all. The options to select categories are there in the Edit Post page (and Quick Edit), they just aren't showing up on the front end.
I have tried flushing the permalinks by saving under Settings > Permalinks, and I have also tried including flush_rewrite_rules();
in my functions.php. Nothing works?
Here is my custom post type code (note: my custom posts work fine with rewrite rules, it's just the categories):
/**
* Registers the 'apc_portfolio' custom post type.
*
* @example register_post_type( $taxonomy, $args );
* @see https://codex.wordpress.org/register_post_type#Parameters
* @todo change public, to false
*/
function apc_register_portfolio_post_type() {
$labels = array(
'add_new_item' => __( 'Add New Portfolio Item', 'detail-factory-2020' ),
'add_new' => __( 'Add New Portfolio', 'detail-factory-2020' ),
'all_items' => __( 'All Portfolio Items', 'detail-factory-2020' ),
'archives' => __( 'Portfolio Item Archives', 'detail-factory-2020' ),
'attributes' => __( 'Portfolio Item Attributes', 'detail-factory-2020' ),
'edit_item' => __( 'Edit Portfolio Item', 'detail-factory-2020' ),
'featured_image' => __( 'Featured Image', 'detail-factory-2020' ),
'filter_items_list' => __( 'Filter Portfolio Items list', 'detail-factory-2020' ),
'insert_into_item' => __( 'Insert into Portfolio Item', 'detail-factory-2020' ),
'items_list_navigation' => __( 'Portfolio Items list navigation', 'detail-factory-2020' ),
'items_list' => __( 'Portfolio Items list', 'detail-factory-2020' ),
'menu_name' => __( 'Portfolio', 'detail-factory-2020' ),
'name_admin_bar' => __( 'Portfolio Item', 'detail-factory-2020' ),
'name' => _x( 'Portfolio Items', 'Post Type General Name', 'detail-factory-2020' ),
'new_item' => __( 'New Portfolio Item', 'detail-factory-2020' ),
'not_found_in_trash' => __( 'Not found in Trash', 'detail-factory-2020' ),
'not_found' => __( 'Not found', 'detail-factory-2020' ),
'parent_item_colon' => __( 'Parent Portfolio Item:', 'detail-factory-2020' ),
'remove_featured_image' => __( 'Remove featured image', 'detail-factory-2020' ),
'search_items' => __( 'Search Portfolio Item', 'detail-factory-2020' ),
'set_featured_image' => __( 'Set featured image', 'detail-factory-2020' ),
'singular_name' => _x( 'Portfolio Item', 'Post Type Singular Name', 'detail-factory-2020' ),
'update_item' => __( 'Update Portfolio Item', 'detail-factory-2020' ),
'uploaded_to_this_item' => __( 'Uploaded to this Portfolio Item', 'detail-factory-2020' ),
'use_featured_image' => __( 'Use as featured image', 'detail-factory-2020' ),
'view_item' => __( 'View Portfolio Item', 'detail-factory-2020' ),
'view_items' => __( 'View Portfolio Items', 'detail-factory-2020' ),
);
$rewrite = array(
'feeds' => false,
'pages' => false,
'slug' => 'work',
'with_front' => true,
);
$args = array(
'can_export' => true,
'capability_type' => 'post',
'exclude_from_search' => false,
'has_archive' => true,
'hierarchical' => false,
'label' => __( 'Portfolio Item', 'detail-factory-2020' ),
'labels' => $labels,
'menu_icon' => 'dashicons-portfolio',
'menu_position' => 5,
'public' => true,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'show_in_admin_bar' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_rest' => true,
'show_ui' => true,
'supports' => array(
'custom-fields',
'editor',
'excerpt',
'post-formats',
'thumbnail',
'title',
),
'taxonomies' => array( 'category' ),
);
register_post_type( 'apc-portfolio', $args );
}
add_action( 'init', 'apc_register_portfolio_post_type', 0 );