WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Types & meta boxes - Am I missing something? (5 posts)

  1. So, I understand adding custom post types and custom taxonomies via functions.php. There are two things I don't understand though.`

    First, here's what I'm working with.

    register_taxonomy('blog_cats', 'post', array(
    'hierarchical' => true,  'label' => 'Blog Categories',
    'query_var' => true, 'rewrite' => true));
    
    add_action( 'init', 'create_my_post_types' );
    
    function create_my_post_types() {
    	register_post_type( 'blog_posts',
    		array(
    			'labels' => array(
    				'name' => __( 'Blog Posts' ),
    				'singular_name' => __( 'Blog Post' )
    			),
    			'public' => true,
    			'description' => __( 'Blog posts post type.' ),
    			'menu_position' => 5,
    			'taxonomies' => array( 'post_tag', 'blog_cats'),
    			'can_export' => true
    		)
    	);
    }

    If my understanding is right, the following part should add the tags meta box to my Blog Post edit/publish page:

    'taxonomies' => array( 'post_tag', 'blog_cats'),

    It doesn't. Doesn't work for 'category' either. What gives?

    -----

    The second thing I'm not getting is that custom taxonomies are automatically added in the form of meta boxes to the baked-in post edit/publish page. That's just fine in some cases, but what if I want to remove some of the meta boxes attached to custom taxonomies? A good example is derived from the above code example. I don't need both categories and blog categories for regular posts. Thoughts?

    Maybe these screencaps will help illustrate the point:

    http://imgur.com/7qxS0.png

    http://i.imgur.com/6fPz1.png

  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    Register your taxonomy inside the function with the post type (prior to the post type).

    Both post types and taxonomies need to be registered at init.

    If that's still problematic, try the action with a higher priority..

    Eg.

    add_action( 'init', 'create_my_post_types', 0 );
  3. Mark,

    Thank you! It was getting late and I knew something was amiss, I'm glad somebody had the answer to this.

    Turns out, this worked great out of the box on my second less-modded install. On the first install, using a WooThemes theme, I had to place the function in another included functions file.

    Either way, thank you very much sir!

  4. Strike that, *sigh*.

    Deactivating plugins to find the conflict. Thanks for all your help.

    **Update: Weird. I deactivated plugins and reactivated one by one. Tags meta box is showing up with the same plugins activated now. Odd.

  5. Mark / t31os
    Moderator
    Posted 3 years ago #

    Glad to hear you have everything working... and happy i could help... :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.