Forums

[resolved] Add category to custom post type (4 posts)

  1. baszer
    Member
    Posted 6 months ago #

    Hello, I am having trouble to add the standard category taxonomy to my custom post type.

    I can add custom made taxonomies to my custom post types.

    I have the following cumstom post type:

    register_post_type('people',
    		array(	'label' => 'People',
    				'public' => true,'show_ui' => true,
    				'show_in_menu' => true,
    				'capability_type' => 'post',
    				'hierarchical' => false,
    				'rewrite' => array('slug' => ''),
    				'query_var' => true,
    				'has_archive' => true,
    				'supports' => array('title','editor','thumbnail',),
    				'taxonomies' => array('category',),
    				'menu_position' => 5,
    				) );

    in taxonomies I added category, but it is not working, what do I do wrong?

    In my custom taxonomy I also have to add on which custom type it has effect on. Do I have to do this also with the standard category?

  2. keesiemeijer
    moderator
    Posted 6 months ago #

    Try it with this:

    add_action('init', 'register_mypost_type');
    function register_mypost_type() {
    register_post_type('people',
    		array(	'label' => 'People',
    				'public' => true,'show_ui' => true,
    				'show_in_menu' => true,
    				'capability_type' => 'post',
    				'hierarchical' => false,
    				'rewrite' => array('slug' => ''),
    				'query_var' => true,
    				'has_archive' => true,
    				'supports' => array('title','editor','thumbnail',),
    				'taxonomies' => array('category',),
    				'menu_position' => 5,
    				) );
    }
  3. baszer
    Member
    Posted 6 months ago #

    @keesiemeijer (dutch? ;) )

    thanks that did the trick, can you also tell me why you have to add that in front? Because I was able to add new people

  4. keesiemeijer
    moderator
    Posted 6 months ago #

    http://codex.wordpress.org/Function_Reference/register_post_type#Description
    http://codex.wordpress.org/Plugin_API/Action_Reference/init
    Not sure why it is needed. Maybe because categories (and other functionality) are only available after WordPress is finished loading.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.