Anyway to assign custom post types to a specific category?

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)

Related posts

Leave a Reply

1 comment

  1. 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