StudioPress Community Forums

StudioPress Community Forums (http://www.studiopress.com/support/index.php)
-   General Discussion (http://www.studiopress.com/support/forumdisplay.php?f=7)
-   -   Custom Post Types & Categories/Tags (http://www.studiopress.com/support/showthread.php?t=99605)

seth17 04-12-2012 11:33 PM

Custom Post Types & Categories/Tags
 
I've created a custom post type called "Projects". I'm trying to get the categories and tags meta boxes to display in the content editor. So far no luck. Not sure what's wrong. Here's the code I've got:
PHP Code:

$labels = array(
    
'name' => _x'Projects' ),
    
'singular_name' => _x'project' ),
    
'add_new' => _x'Add New Project' ),
    
'add_new_item' => __'Add New Project' ),
    
'edit' => __('Edit Project'),
    
'edit_item' => __'Edit Project' ),
    
'new_item' => __'New Project' ),
    
'view' => __'View Project' ),
    
'view_item' => __'View Project' ),
    
'search_items' => __'Search Projects' ),
    
'all_items' => __'All Projects' ),
    
'not_found' => __'No Projects Found.' ),
    
'not_found_in_trash' => __'No Projects Found in Trash.' ),
    
'parent' => __('Projects'), 
    
'menu_name' => __'Projects' ),
    
'parent_item_colon' => ''
);
$args = array(
    
'labels' => $labels,
    
'public' => true,
    
'publicly_queryable' => true,
    
'exclude_from_search' => false,
    
'show_ui' => true,
    
'menu_position' => 5,
    
'menu_icon' => null,
    
'capability_type' => post,
    
'hierarchical' => true,
    
'supports' => array('title''editor''comments''thumbnail''excerpt''custom-fields''revisions''page-attributes''categories''genesis-seo''genesis-layouts', ),
    
'taxonomies' => array('post_tag''category', ),
    
'has_archive' => true,
    
'rewrite' => array('slug' => projects'with_front' => true, ),
    
'query_var' => true,
    
'can_export' => true,
    
'show_in_nav_menus' => true,
);

register_post_type('projects'$args); 


adew 04-13-2012 02:45 AM

Your code looks fine to me, but:

1. Have you hooked that function to 'init'?

2. Assuming yes, have you checked the Screen Options tab in the editor to make sure the metaboxes are visible?

seth17 04-13-2012 07:51 AM

I've check the screen options and it's not there, so it's probably the fact I haven't hooked it to 'init'. I'm not quite sure how to do that. The code above is all I've added for the CPT.

adew 04-13-2012 08:41 AM

You have to register CPT after the taxonomies have been created, hence you need to hook to init.

Do this:

PHP Code:

add_action'init''init_my_cpt' );
function 
init_my_cpt() {

// paste all your existing code here



seth17 04-13-2012 12:25 PM

Thanks Ade, that's just what I needed. Works great. Apparently the tutorial I followed previously had left that part out.

seth17 04-13-2012 03:07 PM

Got another question. In the CPT editor, blog categories and tags are displaying. I was hoping this would create a new taxonomy for the cpt, (so that I could create specific categories for the cpt), but it appears to just be using what's already there. Is there something else I need to do make it behave like that?

adew 04-13-2012 09:17 PM

Quote:

Originally Posted by seth17 (Post 505443)
Got another question. In the CPT editor, blog categories and tags are displaying. I was hoping this would create a new taxonomy for the cpt, (so that I could create specific categories for the cpt), but it appears to just be using what's already there.

Yes, it's using normal Post Tags and categories because that's exactly what you specified in your CPT code:
PHP Code:

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


Quote:

Originally Posted by seth17 (Post 505443)
Is there something else I need to do make it behave like that?

You mean you want to create a custom taxonomy? If so, take a look at register_taxonomy().

You can add your register_taxonomy code within the existing function, but place it above the CPT code. You then need to change this line in your CPT code to point to your new taxonomy:
PHP Code:

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


seth17 04-13-2012 11:26 PM

Super. Thanks again!

adew 04-14-2012 04:55 AM

You're welcome.

Since this is resolved, I'll close the thread.


All times are GMT -5. The time now is 04:39 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.