I was able to create multiple Custom Post Type, but having trouble in registering Taxonomies. I would like to create each CPT has a their own Taxonomies not shared.

UPDATE!

Hi All, Thank you for answering my question. I already fixed it by doing this:

function CPT-1(){
$labels = array(
    'name'                => __( 'Careers' ),
    'singular_name'       => __( 'Career'),
    'menu_name'           => __( 'Careers'),
    'parent_item_colon'   => __( 'Parent Careers'),
    ..etc..
);
$args = array(
    'label'               => __( 'career'),
    'description'         => __( 'careers'),
    ....etc...
);
register_post_type( 'cpt1', $args );
}

    function CPT2(){
$labels = array(
    'name'                => __( 'Careers' ),
    'singular_name'       => __( 'Career'),
    'menu_name'           => __( 'Careers'),
    ...etc...
);
$args = array(
    'label'               => __( 'career'),
    'description'         => __( 'careers'),
    'labels'              => $labels,
    'supports'            => array( 'title', 'editor', 'excerpt', 'author', 
  .....etc.....
);
register_post_type( 'cpt2', $args );
}

function cma_register_taxonomies() {
$taxonomies = array(
    array(
        'slug'         => 'department',
        'single_name'  => 'Department',
        'plural_name'  => 'Department',
        'post_type'    => 'cpt1',
        'rewrite'      => array( 'slug' => 'department' ),
    ),
    array(
        'slug'         => 'job-type',
        'single_name'  => 'Type',
        'plural_name'  => 'Types',
        'post_type'    => 'cp2',
        'hierarchical' => false,
    )
    ),
);
foreach( $taxonomies as $taxonomy ) {
    $labels = array(
        'name' => $taxonomy['plural_name'],
        'singular_name' => $taxonomy['single_name'],
        'search_items' =>  'Search ' . $taxonomy['plural_name'],
        'all_items' => 'All ' . $taxonomy['plural_name'],
        'parent_item' => 'Parent ' . $taxonomy['single_name'],
        'parent_item_colon' => 'Parent ' . $taxonomy['single_name'] . ':',
        'edit_item' => 'Edit ' . $taxonomy['single_name'],
        'update_item' => 'Update ' . $taxonomy['single_name'],
        'add_new_item' => 'Add New ' . $taxonomy['single_name'],
        'new_item_name' => 'New ' . $taxonomy['single_name'] . ' Name',
        'menu_name' => $taxonomy['plural_name']
    );

    $rewrite = isset( $taxonomy['rewrite'] ) ? $taxonomy['rewrite'] : array( 'slug' => $taxonomy['slug'] );
    $hierarchical = isset( $taxonomy['hierarchical'] ) ? $taxonomy['hierarchical'] : true;

    register_taxonomy( $taxonomy['slug'], $taxonomy['post_type'], array(
        'hierarchical' => $hierarchical,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => $rewrite,
    ));
}

}
  • How you register your taxonomies and CPT's ? Can you share your code? – Laxmana May 5 '17 at 12:10

Try this:

function post_type_categories() {
        $field_args = array(
            'labels' => array(
            'name'              => 'Categories', 'taxonomy general name',
            'singular_name'     => 'Category', 'taxonomy singular name',
            'search_items'      => 'Search categories',
            'all_items'         => 'All categories',
            'parent_item'       => 'Parent category',
            'parent_item_colon' => 'Parent category:',
            'edit_item'         => 'Edit category',
            'update_item'       => 'Edit category',
            'add_new_item'      => 'Add new category',
            'new_item_name'     => 'New category',
            'menu_name'         => 'Categories',
            ),
            'hierarchical' => true
        );
        register_taxonomy( 'post_type_categories', '{your_post_type_name}', $field_args );
    }    
  • 1
    Could you edit your answer and provide detail on what this code does and how this would solve the original question, please? Usually code only answers without any explanation are frowned upon. – Howdy_McGee May 6 '17 at 14:33

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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