Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Lucas Santos
Lucas Santos
19,315 Points

Why don't I see the options to assign a category in my custom post type??

Hey guys so I am using the Custom Post type UI and Custom Fields plugins and when I create a custom field all the way at the bottom it gives you the options in a checkbox of what you do and do not want to show from wordpress's standard fields. Anyone who uses custom fields should know what im talking about. So any ways iv unchecked all of the fields in the bottom and only want CATEGORY to display so I can assign each custom post type to a category as you would with a regular post type.

The Problem:

Problem is when I go create a new custom post types I see all of my custom fields but I don't see my little "categories" menu show up and for some reason I see "attributes" showing up and custom field options at the bottom.

I do not know why this is not working but I did not want attributes or the custom fields options to show at the bottom of my custom post type. Am I missing something? Am I doing something wrong? Why wont categories show up even tho I checked it in the custom fields options???

2 Answers

Hi Lucas,

Category is actually a TAXONOMY for the built-in Post post type.

What that mean is it won't be available with any other custom post type, But you can register you own custom taxonomy and attach it to each custom post type.

To register your taxonomy, You can add this code right bellow your register_post_type function:

<?php 

add_action('init', 'create_books_tax');

function create_books_tax()
{
    register_taxonomy(
        'section', // taxonomy 
        'books', // custom post type
        array(
            'label'             => __('Sections', 'your-text-domain'),
            'hierarchical'      => true,
            'show_ui'           => true,
            'show_admin_column' => true,
            'show_in_nav_menus' => true,
            'show_tagcloud'     => true,
            'public'            => true
        )
    );
}

?>

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

Lucas Santos
Lucas Santos
19,315 Points

So after adding the code you provided to my functions.php above that portion of code I will have to register the custom tax with another function called register_post_type?

The part thats confusing me here is register_post_type. Why do I need it if I have already created a custom post type with the plugin? or do I still need it to work with register_taxonomy?

You don't have to add my code since your using custom post type ui plugin.

You can register your own taxonomy via the plugin directly and choose which post type to attach it with.

Lucas Santos
Lucas Santos
19,315 Points

Yeah I figured since that plugin is so well made. I prefer coding things out all the time but when it comes to the custom post type or the custom fields plugin id much rather do that because there so well made being fast and easy to use. Thank you so much for your help!