Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Trying to show the category page for a custom post type 'cast' with category taxonomy WordPress

  • SOLVED

Trying to show the category page for a custom post type 'cast' with category taxonomy, which template file should I use?

// create casting content type------------------------

add_action( 'init', 'create_casting' );
function create_casting() {

$labels = array(
'name' => _x('Casting', 'post type general name'),
'singular_name' => _x('Cast', 'post type singular name'),
'add_new' => _x('Add New Cast', 'Testimonial'),
'add_new_item' => __('Add Cast'),
'edit_item' => __('Edit Cast'),
'new_item' => __('New Cast'),
'view_item' => __('View Cast'),
'search_items' => __('Search Casting'),
'not_found' => __('No Cast found'),
'not_found_in_trash' => __('No Cast found in Trash'),
'parent_item_colon' => '',
);

$supports = array('title', 'category');



register_post_type( 'cast',
array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'supports' => $supports,
'query_var' => true,
'menu_icon' => 'dashicons-id-alt',
'taxonomies' => array('category'),
'rewrite' => array('slug' => 'casting'),
)
);

}

Answers (1)

2019-10-09

Reigel Gallarde answers:

I have a feeling that you're doing this the wrong way.
You are sharing category with "cast" and "post" post types.

I suggest you create new taxonomy for "cast"
use this generator, so it will be easy https://generatewp.com/taxonomy/
you can also enhance your "cast" with this generator https://generatewp.com/post-type/

then read about template hierarchy here: https://developer.wordpress.org/themes/basics/template-hierarchy/
if you'll follow my suggestion, you can achieve what you want without problems, scroll down to "Custom Taxonomies" in the last given link.


Nick comments:

You are tight, added a taxonomy and all working now, cheers


Reigel Gallarde comments:

Please accept my answer if this solved your problem. Cheers!