I have declared a selection of custom post types as an array, allowing post_tags
but not categories
:
// Add Multiple Custom Post Types
add_action('init', 'all_custom_post_types');
function all_custom_post_types() {
$types = array(
array('the_type' => 'mama',
'single' => 'Mama',
'plural' => 'Mamas'),
array('the_type' => 'webinar',
'single' => 'Webinar',
'plural' => 'Webinars'),
array('the_type' => 'video',
'single' => 'Video',
'plural' => 'Videos'),
array('the_type' => 'discount',
'single' => 'Discount',
'plural' => 'Discounts'),
array('the_type' => 'faq',
'single' => 'FAQ',
'plural' => 'FAQs'),
);
foreach ($types as $type) {
$the_type = $type['the_type'];
$single = $type['single'];
$plural = $type['plural'];
$labels = array(
'name' => _x($plural, 'post type general name'),
'singular_name' => _x($single, 'post type singular name'),
'add_new' => _x('Add New', $single),
'add_new_item' => __('Add New '. $single),
'edit_item' => __('Edit '.$single),
'new_item' => __('New '.$single),
'view_item' => __('View '.$single),
'search_items' => __('Search '.$plural),
'not_found' => __('No '.$plural.' found'),
'not_found_in_trash' => __('No '.$plural.' found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'has_archive' => true,
'menu_position' => 5,
'supports' => array('title','editor','thumbnail','author','comments','excerpt'),
'show_in_menu' => true,
'show_in_nav_menus' => true,
'exclude_from_search' => true,
'taxonomies' => array( 'post_tag' ),
);
register_post_type($the_type, $args);
}
}
As can be seen, the arguments allow for public => true;
and has_archive => true;
.
I've also set up a custom taxonomy to work as Categories for CPTs only:
function topics() {
$labels = array(
'name' => _x( 'Topics', 'taxonomy general name' ),
'singular_name' => _x( 'Topic', 'taxonomy singular name' ),
'search_items' => __( 'Search Topics' ),
'all_items' => __( 'All Topics' ),
'parent_item' => __( 'Parent Topic' ),
'parent_item_colon' => __( 'Parent Topic:' ),
'edit_item' => __( 'Edit Topic' ),
'update_item' => __( 'Update Topic' ),
'add_new_item' => __( 'Add New Topic' ),
'new_item_name' => __( 'New Topic' ),
'menu_name' => __( 'Topics' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'has_archive' => true,
);
register_taxonomy( 'topics', array( 'discount', 'video', 'webinar' ), $args );
}
add_action( 'init', 'topics', 0 );
My problem is that when calling the archive pages for these The CPTs are simply not being found. Tags shared by CPTs and standard posts return only the latter, and topics
archives or tag archives with only CPTs assigned return empty.
I can see from my markup that the correct templates are being called (tag.php, taxonomy.php) but all are empty.
Why would this be happening?