Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separate categories for post types

Is there any way to create custom post type with separate categories in wordpress?

Example:

Post type "News" should have categories "World" and "Local". Post type "Products" should have categories: "Software" and "hardware" and I do not want to have option to set "Software" category to "News" post type.

Is there any way to handle this?

like image 641
Martin Strouhal Avatar asked Feb 10 '12 13:02

Martin Strouhal


People also ask

How do I list categories of a custom post type?

use get_terms() function to fetch custom taxonomy by its slug, in your case slug is dining-category.

What is post category?

category A post means any post, which, having regard to its scale of pay or emoluments, would, if such post had been in the Central Government, be classified as a Group A post under.

How do I make multiple post types in WordPress?

In order to configure settings, navigate to [ WordPress Admin -> Settings -> Multiple Post Types Order ], where you can see two options: Show/Hide Re-Ordering Interface for Post Types. No of times Re-Ordering required.

How do I create a custom post category in WordPress?

There are a lot of options to sift through, so carefully go over what is available. At the bottom of the list, click the “Categories” box for built-in taxonomies. As you can see, you can also choose to add tags to the custom post type as well. This checkbox is directly under the “Categories” option.


1 Answers

You can create custom post type by following example code:

function ts_post_type_test() {
    register_post_type( 'Test',
                array( 
                'label' => __('Test'), 
                'public' => true, 
                'show_ui' => true,
                'show_in_nav_menus' => false,
                'menu_position' => 5,
                'capability_type' => 'post',
                'texonomies' => array('category'),
                'supports' => array( 'title','editor','thumbnail'),
                ) 
    );
}

the wordpress site link : http://codex.wordpress.org/Function_Reference/register_post_type

For the Create separate category for particular post use following link:

http://codex.wordpress.org/Function_Reference/register_taxonomy

Example code:

register_taxonomy('name of taxonomy', 'post name',array("hierarchical" => true,"label" => "Label Category","singular_label" => "label of taxonomy",'update_count_callback' => '_update_post_term_count','query_var' => true,'rewrite' => array( 'slug' => 'slug name of new registered taxonomy', 'with_front' => false ),'public' => true,'show_ui' => true,'show_tagcloud' => true,'_builtin' => false,'show_in_nav_menus' => false));
like image 116
gr8nilay Avatar answered Sep 28 '22 19:09

gr8nilay