Forums

Categories and tags not showing in custom post (12 posts)

  1. kirisu_kun
    Member
    Posted 1 year ago #

    Hi There,

    I've registered a custom post type, and it's all working fine - however, I can't get the categories or tags boxes to appear. I'm wanting to associate the default post categories with my custom posts. The code I'm using is:

    register_post_type('games',
    	array(
    	'description' => 'Game custom post type',
    		'show_ui' => true,
    		'exclude_from_search' => false,
    		'labels' => array(
    			'name' => 'Games',
    			'singular_name' => 'Game',
    			'add_new' => 'Add New Games',
    			'add_new_item' => 'Add New Game',
    			'edit' => 'Edit Games',
    			'edit_item' => 'Edit Game',
    			'new_item' => 'New Game',
    			'view' => 'View Games',
    			'view_item' => 'View Game',
    			'search_items' => 'Search Games',
    			'not_found' => 'No games found',
    			'not_found_in_trash' => 'No games found in Trash',
    			'parent' => 'Parent Game',
    		),
    		'public' => true,
    		'supports' => array('title','editor','revisions','thumbnail','author'),
    		'taxonomies' => array('category', 'post_tag'),
    		'rewrite' => array('slug' => 'games', 'with_front' => false),
    		)
    	);

    I have seen this documented on a few websites, which state that this is the correct method - however it's just not working for me.

    Any help would be appreciated.

    Thanks,
    Chris

  2. Getzel Rubashkin
    Member
    Posted 1 year ago #

    Dealing with the same problem. Assigning custom taxonomies to the custom post type is working, but regular categories and tags are not...

  3. Getzel Rubashkin
    Member
    Posted 1 year ago #

    While you are figuring out what is wrong, the long form will do the job:
    register_taxonomy_for_object_type('category', 'custom-type');

    Just make sure to call that after the init function that creates the post type.

  4. danmandle
    Member
    Posted 1 year ago #

    Any solution to this problem? I'm having it too and there doesn't seem to be any other support around. Below is the code that I'm using:

    register_post_type('portfolio', array(
    	'label' => __('Portfolio Items'),
    	'singular_label' => __('Portfolio Item'),
    	'public' => true,
    	'show_ui' => true,
    	'menu_position' => 5,
    	'capability_type' => 'post',
    	'hierarchical' => false,
    	'rewrite' => false,
    	'query_var' => false,
    	'supports' => array('title', 'editor', 'thumbnail', 'revisions', 'custom-fields'),
    
    	'can_export' => true
    ));
  5. Getzel Rubashkin
    Member
    Posted 1 year ago #

    The long form did the trick for me (see my previous post)

  6. snails07
    Member
    Posted 1 year ago #

    That worked for me. Cheers

  7. marktcorbin
    Member
    Posted 1 year ago #

    Hey, had the same issue so was pleased to find this thread, but I'm still not quite getting there...

    I'm creating custom post types inside functions.php in my theme- a child theme of twenty-ten

    Is it ok to put the register_taxononomy_for_object_type immediately after the register_post_type function?

    The post types are registering fine but the tags and categories boxes are still disappointingly absent.

    Any help appreciated

  8. Getzel Rubashkin
    Member
    Posted 1 year ago #

    Like I said, "Just make sure to call that after the init function that creates the post type."

    You are presumably using add_action to trigger the custom post type. You'll want to use add_action to trigger the long form taxonomy register AFTER the one that adds the post type.

  9. marktcorbin
    Member
    Posted 1 year ago #

    Thank you! I wasn't using add_action - I just had `register_post_type(...);
    register_taxonomy_for_post_type(...); `
    naked in functions.php

  10. velograph
    Member
    Posted 1 year ago #

    My custom post type categories disappeared one day. I found this thread and adding in

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

    did the trick.

    Thanks!

  11. graemeboy
    Member
    Posted 10 months ago #

    register_taxonomy_for_object_type('category', 'custom-type');

    It worked! Thanks!

  12. asthecrowspins
    Member
    Posted 7 months ago #

    I had the same problem and just worked it out. You shouldn't have to use register_taxononomy_for_object_type at all if you set the taxonomy option in register_post_type.

    In order to get the taxonomies to work you have to attach your register_post_type function to the init hook. For example, in your functions.php:

    add_action('init', 'my_post_type_maker');
    function my_post_type_maker() {
        $args = array(/*your custom post type arguments here*/);
        register_post_type('book', $args);
    }

    If you don't hook your register_post_type into the init hook everything seems to work except adding support for taxonomies, which can certainly be confusing.

Topic Closed

This topic has been closed to new replies.

About this Topic