2
votes

I have created a Custom Post Type that has a series of different categories that need their own landing page. Right now I have gone through WP Post Type Templates but I still cannot get the category page to show up. Right now the CPT category pages just 404.

I have tried to do the following:

  1. Register post type archives based off this.
  2. Create archive template files using archive-teams.php and archive-team.php.
  3. Tried using category-teams.php and category-team.php.
  4. Flushed permalinks 1 Million times.

Here is how I am registering the post type and taxonomy:

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

  register_taxonomy(
    'teams',
    array(),
    array(
      'hierarchical' => true,
      'labels' => array
      (
        'name' => _x('Teams', 'taxonomy general name'),
        'singular_name' => _x('Team', 'taxonomy singular name')
      ),
      'show_ui' => true,
      'show_admin_column' => true,
      'query_var' => 'team',
      'rewrite' => array(
          'slug' => 'our-team',
      ),
    )
  );

  register_post_type(
    'team',
    array(
      'labels' => array
      (
        'name' => _x('Team Members', 'post type general name'),
        'singular_name' => _x('Team Member', 'post type singular name')
      ),
      'supports' => array('title', 'editor', 'thumbnail'),
      'public' => true,
      'rewrite' => array
      (
        'slug' => 'our-team/%teams%',
        'with_front' => false
      ),
      'query_var' => 'team',
      'has_archive' => 'team',
      'taxonomies' => array( 'teams','category','post_tag' ),
    )
  );
}
2
What you need in this.. - Mr. HK
What's problem are you facing? - Mr. HK
@Mr.HK the categories template is not working/showing up and gets a 404. - alexmattorr
Okay wi;ll check it, And let you know - Mr. HK
What links are you using and what are you expecting? The template should be "taxonomy-teams.php" not "category-teams.php" - StephanieQ

2 Answers

0
votes

You should try archive-$customposttype.php for editing the archive file, including category page template for custom post types. You can read more here https://developer.wordpress.org/themes/basics/template-hierarchy/

0
votes

Give this a try. I am sure this will work:-

  1. In your functions.php, put this line of code under add_action hook:-
register_taxonomy('category_events', array('events'), array('hierarchical' => true, 'label' => 'Events','show_admin_column' => true, 'singular_label' => 'Events', 'rewrite' => true));

You can name your slugs accordingly.

  1. Name your Taxonomy file like this:

taxonomy-{slug}.php # Where slug is the name of the first argument provided in the above code snippet.

  1. refresh the settings by going to Settings > Permalinks.

And boom you have your custom taxonomy up and ready.

Credits and Thanks to Harun Mansuri(***) for helping me with this solution