2

I have created a custom post type 'hotel' and custom 'taxonomy' so when administrator creates a new hotel and saves it it related custom taxonomy automatically get created but I don't want to show custom metabox in the admin side hotel edit page so for that I used WordPress function but nothing happen.

My custom post code

  $Hotel_labels = array(
'name' => _x('Hotels', 'post type general name'),
'singular_name' => _x('Hotel', 'post type singular name'),
'add_new' => _x('Add New', 'Hotel'),
'add_new_item' => __('Add Hotel'),
'edit_item' => __('Edit Hotel'),
'new_item' => __('New Hotel'),
'all_items' => __('All Hotels'),
'view_item' => __('View Hotel'),
'search_items' => __('Search Hotel'),
'not_found' =>  __('No Hotel found'),
'not_found_in_trash' => __('No Hotel found in Trash'), 
'parent_item_colon' => '',
'menu_name' => __('Hotel'),
);

register_post_type('Hotel',$Hotel_args);

Custom taxonomy code

$Package_labels = array(
'name' => _x( 'Package Hotels', 'taxonomy general name' ),
'singular_name' => _x( 'hotel', 'taxonomy singular name' ),
'search_items' =>  __( 'Search hotels' ),
'popular_items' => __( 'Popular hotels' ),
'all_items' => __( 'All hotels' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit hotel' ), 
'update_item' => __( 'Update hotel' ),
'add_new_item' => __( 'Add New hotel' ),
'new_item_name' => __( 'New hotel Name' ),
'separate_items_with_commas' => __( 'Separate hotels with commas' ),
'add_or_remove_items' => __( 'Add or remove hotels' ),
'choose_from_most_used' => __( 'Choose from the most used hotels' ),
'menu_name' => __( 'Package Hotels' ),
);

 register_taxonomy('package_hotel','package',array(
'hierarchical' => false,
'labels' => $Package_labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'show_in_nav_menus' => false,
'rewrite' => array( 'slug' => 'hotels' ),
));

code to remove custom taxonomy metabox form custom post type hotel page

function my_remove_meta_boxes() {
    remove_meta_box('tagsdiv_hotels', 'Hotel', 'side');
}

add_action( 'admin_menu', 'my_remove_meta_boxes' );
  • 1
    Thanks everyone for your solution but I found my solution that I was not giving the metabox id attribute to remove_meta_box('tagsdiv_hotels', 'Hotel', 'side'); in right way . so the right way is to append tagsdiv_in the beginning and after that add your metabox is like this remove_meta_box('tagsdiv-package_hotel', 'hotel', 'side'); – Abhimanue Tamang Dec 3 '12 at 14:30
1

Change your taxonomy registration parameter show_ui to false...

 register_taxonomy('package_hotel','package',array(
'hierarchical' => false,
'labels' => $Package_labels,
'show_ui' => false,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'show_in_nav_menus' => false,
'rewrite' => array( 'slug' => 'hotels' ),
));
  • This will also hide the menu item for editing the taxonomy which may not be desired. – Derek S Sep 29 '16 at 16:12
1

change your metabox id "tagsdiv_hotels "package_hotel"

function my_remove_meta_boxes() {
        remove_meta_box('package_hotel', 'Hotel', 'side');
    }

    add_action( 'admin_menu', 'my_remove_meta_boxes' );
  • Explain your answer. A code snippet is not an answer here. – fuxia Dec 4 '12 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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