1

I've installed Custom Post Type UI plugin on my client's site. I have registered two new post types called Resources and Case Studies. I've enabled them to have categories and tags support. All of this works fine.

However, I want to be able to show a list of categories for only the case studies in the case studies sidebar and a list of the categories for the resource posts in the resources sidebar. Right now they appear to overlap and share categories and tags. Is there something I am missing?

If you view this page you will see the sidebar shows http://goconcentric.com/resources/resource-2/ case studies as an option when this is a resource post. Similarly case study posts have a link to resources. I want the categories to be separate and only show on the pages in their hierarchy.

  • This is something WordPress can't do natively. See this related question. – Milo Apr 27 '17 at 23:13
  • In this example it says they have a shared taxonomy 'flag'. In my case I don't want anything shared by the two posts types. Is this still applicable? – Kristin P Apr 27 '17 at 23:21
  • Then you probably want to create two new custom taxonomies, one for each post type. – Milo Apr 27 '17 at 23:55
0

You should use not the categories, but two different custom taxonomies (it's like custom categories, if you're not familiar with with WordPress taxonomies).

You can create two separate taxonomies via Custom Post Type UI plugin. screenshot

And select to which of the post types, created taxonomy belongs. Also select that custom taxonomy is hierarchical, so it's displayed like a category , not like tags.

  • I am pretty sure that is what I already did here is a screenshot: dropbox.com/s/dwnwn4gc6l2tv5e/… Do I need to turn the category function off? – Kristin P Apr 27 '17 at 23:16
  • In taxonomies tab you have 2 default WordPress taxonomies its: categories and post_tag, you should create additional taxonomies as in the very bottom of the page you can see: No taxonomies registered for display. So that means that you are using default categories, you should create new taxonomy and assign it to your custom post type. Because taxonomies assigned to different post types as you've experienced, inherits all the data from any post type they are assigned. Usually you want to create different taxonomy for each post type you want to have categorization function. – Eimantas Kasperiūnas Apr 27 '17 at 23:32
  • My hero!! Thank you! I am new to this aspect of Wordpress development so the taxonomy vs post type wasn't clear to me. I removed the category support on the post types and created separate taxonomies for each and now it works wonderfully! – Kristin P Apr 27 '17 at 23:54
  • Oops perhaps I responded too soon! I see the correct ones displaying now on the sidebar but when I click them they go to a page with nothing there even though posts have been assigned to that category. Is there a setting i need to change to make posts show up with that category? – Kristin P Apr 27 '17 at 23:58
  • Well It could be an issue that custom post type and taxonomy has the same name, because it's redirecting you to 404 page it seems. After changing slugs of taxonomy go to Settings >> Permalinks and resave structure for links to update. Custom post type and taxonomy allways should have different names or at least different slugs. – Eimantas Kasperiūnas Apr 28 '17 at 0:04
0

please check now for working code custom post and category

function team_custome_post(){
    $labels = array(
            'name' => __('Teams', 'team'),
            'singular_name' => __('Teams ', 'team'),
            'add_new' => __('New Teams ', 'team'),
            'add_new_item' => __('Add new Teams ', 'team'),
            'edit_item' => __('Edit Teams ', 'team'),
            'new_item' => __('New Teams ', 'team'),
            'view_item' => __('View Teams ', 'team'),
            'search_item' => __('Search Teams ', 'team'),
            'not_found' => __('No The Teams  Found', 'team'),
            'not_found_in_trash' => __('No The Teams  found in trash', 'team')
        );
    $args = array(
            'labels' => $labels,
            'public' => true,
            'menu_icon' => 'dashicons-groups',
            'supports' => array(
                'title',
                'editor',
                'thumbnail'             
                ),
        );
    register_taxonomy(
        'teamcategory',
        'team',
        array(
            'label' => __( 'Teams Category' ),
            'rewrite' => array( 'slug' => 'teamcategory' ),
            'hierarchical' => true,
        )
    );   
    register_post_type('team', $args);
}

add_action('init', 'team_custome_post' );
  • 1
    Please explain how this answers the question. – Milo Apr 28 '17 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.