Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there anyway to assign all new posts that have a custom post_type to a specific category? For example, say I have a post_type that is for Actors. Is there anyway to assign any post that is under Actors to a "People" category? (but without displaying the Category box in the WordPress Admin)

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

you can first remove the category meta box from Actors post type edit screen like this

 function remove_custom_taxonomy()
 {
    remove_meta_box( 'categorydiv', 'custom_post_slug', 'side' );
 }

add_action( 'admin_menu', 'remove_custom_taxonomy' );

then create a function that will add the category on save_post

function default_category($post_id){
     // check autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }

     // check for post type
    if ('Actors' == $_POST['post_type']) {
            $Default_category_id = '23';
        wp_set_post_terms( $post_id,$Default_category_id , 'category', ture );
     }

}

hope this helps

share|improve this answer
    
It appears to be adding the custom post types to the correct category, but when I look on the Categories page in the WordPress admin it says 0. Any ideas why the correct number isn't showing up? –  user1462 Jan 31 '11 at 18:29
    
I'm not sure but i think it has to do code, if you paste it here i could get a better idea. by code i mean the register_post_type function and any other custom code in relevance –  Bainternet Jan 31 '11 at 18:47
    
I figured it out. I needed to add "capability_type=>'post'" to the register_post_type arguments in order to get it to appear. –  user1462 Jan 31 '11 at 19:35
    
glad i could help :) –  Bainternet Jan 31 '11 at 20:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.