• Hi guys,

    I’m using a couple of custom post types. They both work fine and both have Categories. However, the categories are shared between both of my custom post types.
    I have one post type called Food and one called Takeaway. Whenever I add/remove a catergory to Food, the same happens for the Takeaway category.
    I want the two custom post types to have their own set of categories.
    How can I achieve this?

    Any help is appreciated.
    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello drinkingsouls,

    maybe you are using the same name for both taxonomies when you register it?
    Check the first parameter fo your “register_taxonomy()” calls.
    I think if they are equal in two or more calls there will be a conficlt.

    register_taxonomy(
    	'prefix-category',
    	'post-type',
    	array(
    		'hierarchical' => true,
    		'label'        => __( 'Categories' ),
    		'rewrite'      => array( 'slug' => 'prefix-category' )
    	)
    );

    Read more about “register_taxonomy()”

    Hope I could help you.

    Thread Starter drinkingsouls

    (@drinkingsouls)

    /* Food post type for menu */
    function create_food_post_type() {
    	register_post_type( 'food',
    		array(
    		'labels' => array(
    			'name' => __( 'Food' ),
    			'singular_name' => __( 'food' ),
    		),
    		'rewrite' => array( 'slug' => 'food', 'with_front' => true ),
    		'public' => true,
    		'has_archive' => true,
    		'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields'),
    		'taxonomies' => array('category'),
    		)
    
    	);
    	flush_rewrite_rules( false );
    }
    
    add_action( 'init', 'create_food_post_type' );
    
    /* Branches post type */
    function create_branch_post_type() {
    	register_post_type( 'branches',
    		array(
    		'labels' => array(
    			'name' => __( 'Branches' ),
    			'singular_name' => __( 'branch' ),
    		),
    		'rewrite' => array( 'slug' => 'branches', 'with_front' => true ),
    		'public' => true,
    		'has_archive' => true,
    		'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields'),
    		'taxonomies' => array('category'),
    		)
    
    	);
    	flush_rewrite_rules( false );
    }
    add_action( 'init', 'create_branch_post_type' );

    This is my code for two of my custom post types – branches and food.
    They share the same categories but they need to have their own individual categories. Can you spot what might be wrong here?

    Hello,

    you still have to register your taxonomies:

    <?php
    
    /* Food post type for menu */
    function create_food_post_type() {
    	register_post_type( 'food',
    		array(
    		'labels' => array(
    			'name' => __( 'Food' ),
    			'singular_name' => __( 'food' ),
    		),
    		'rewrite' => array( 'slug' => 'food', 'with_front' => true ),
    		'public' => true,
    		'has_archive' => true,
    		'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields'),
    		)
    
    	);
    	flush_rewrite_rules( false );
    
    	register_taxonomy(
    		'food-category',
    		'food',
    		array(
    			'label' => __( 'Categories' ),
    		)
    	);
    }
    
    add_action( 'init', 'create_food_post_type' );
    
    /* Branches post type */
    function create_branch_post_type() {
    	register_post_type( 'branches',
    		array(
    		'labels' => array(
    			'name' => __( 'Branches' ),
    			'singular_name' => __( 'branch' ),
    		),
    		'rewrite' => array( 'slug' => 'branches', 'with_front' => true ),
    		'public' => true,
    		'has_archive' => true,
    		'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields'),
    		)
    
    	);
    	flush_rewrite_rules( false );
    
    	register_taxonomy(
    		'branches-category',
    		'branches',
    		array(
    			'label' => __( 'Categories' ),
    		)
    	);
    }
    add_action( 'init', 'create_branch_post_type' );
    Thread Starter drinkingsouls

    (@drinkingsouls)

    Hi guys,
    I’m still looking for a solution to this 7 months on. The code in the above post actually successfully creates custom post types but instead of custom categories they have custom post tags. I modified the code to:

    function create_barbering_post_type() {
    	register_post_type( 'barbering',
    		array(
    		'labels' => array(
    			'name' => __( 'Barbering' ),
    			'singular_name' => __( 'barbering' ),
    		),
    		'rewrite' => array( 'slug' => 'barbering', 'with_front' => true ),
    		'public' => true,
    		'has_archive' => true,
    		'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields'),
    		'taxonomies'  => array( 'category' ),
    
    		)
    
    	);
    	flush_rewrite_rules( false );
    
    	register_taxonomy(
    		'barbering-category',
    		'barbering',
    		array(
    			'label' => __( 'Categories' ),
    		)
    	);
    }
    
    add_action( 'init', 'create_barbering_post_type' );

    Then the custom post type ‘Barbering’ has a category option, however when I create another custom post type with the same code the categories are shared between them.
    How can I create custom post types with their own individual categories?
    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Post Type Categories’ is closed to new replies.