Custom Post Type Taxonomies (2 posts)

  1. StevieG
    Posted 5 years ago #

    Ading a new Custom Post type I need to have the existing category and post_tag taxonomies. My code is here

    register_post_type('im_directory', array(
    	'label' => __('Directory'),
    	'singular_label' => __('Directory'),
    	'public' => true,
    	'show_ui' => true, // UI in admin panel
    	'_builtin' => false, // It's a custom post type, not built in!
    	'_edit_link' => 'post.php?post=%d',
    	'capability_type' => 'post',
    	'hierarchical' => true,
    	'supports' => array('title','editor','thumbnail','excerpt'),
    	'rewrite' => array("slug" => "directory"),
    	'taxonomies' => array('post_tag','category'),
    	'menu_position' => 5

    The problem is that I am not seeing the Category and Tag when I go to add a new post. Any ideas?

  2. Mark / t31os
    Posted 5 years ago #

    Where are you placing this code?

    The post type needs to be registered on init..

    add_action( 'init', 'register_my_post_type' );
    function register_my_post_type() {
    	register_post_type( 'im_directory', array(
    		'label' => __('Directory'),
    		'singular_label' => __('Directory'),
    		'capability_type' => 'post',
    		'hierarchical' => true,
    		'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
    		'rewrite' => array( "slug" => "directory" ),
    		'taxonomies' => array( 'post_tag', 'category' ),
    		'menu_position' => 5
    	) );

    NOTE: I removed some args, there's no need to include them when you're using the default value for a given arg.

    If that's still problematic, try changing the action priority..

    Higher value - Lower priority

    add_action( 'init', 'register_my_post_type', 1000 );

    Lower value - Higher priority

    add_action( 'init', 'register_my_post_type', 0 );

    Hope that helps.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic