1
votes

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'),
);



$Hotel_args = array(
    'labels' => $Hotel_labels,
    'public' => true,
    'rewrite' => array('slug' => 'Hotel'),
    'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'has_archive' => true, 
    'hierarchical' => false,
    'menu_position' => 100,
    'supports' => array( 'title', 'editor', 'author', 'thumbnail' ),
    'taxonomies' => array('hotel_facilities','package_hotel','post_tag')
);

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' );
4

4 Answers

0
votes

Change register_taxonomy() : you have kept

'show_ui' => true,

change it to

'show_ui' => false,

this argument determines whether or not a user interface should be displayed to manage the taxonomy. As you don't want it, you have to set it to false.

7
votes

Since WordPress 3.8 version there is a meta_box_cb argument available. Just change this argument to false in your arguments definition so

$args = array(
    'hierarchical'               => false,
    'public'                     => true,
    'show_ui'                    => true,
    'show_in_menu'               => true,
    'meta_box_cb'                => false,
);

This will leave a sub-menu item under your custom post type but will remove a meta box on post edit page.

1
votes

change meta box id enter code here

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

0
votes

Ok now the example given in Wordpress.org is like this


`remove_meta_box($custom_taxonomy_slug.'div', $custom_post_type, 'side' );`

    // $custom_taxonomy_slug is the slug of your taxonomy, e.g. 'genre' )
    // $custom_post_type is the "slug" of your post type, e.g. 'movies' )

which further directs to write syntax for metabox attribute in the function like this remove_meta_box( 'submitdiv', 'custom_post_id', 'side' );


and in my case the syntax for custom metabox attribute which worked is like this remove_meta_box('tagsdiv-package_hotel', 'hotel', 'side'); so instead of appending div at the end append tagsdiv_ in the begnning eg:- tagsdiv_$your_custom_taxonomy_id