I have a post type with 7 (count it SEVEN!) taxonomy tag boxes. By default, the only options to display these metaboxes are – 7 small metaboxes on the right side stacking or turn these tag metaboxes into Long metaboxes and stack them below the main editor.
What I’d rather do is bring all the metaboxes into 1 big metabox below the editor, stacking them in a 3×3 grid (really it would be 3 per row with 1 remainder).
My question is when it comes to metaboxes that WordPress creates do I have any control on how or where it is displayed? Is it possible to group these metaboxes in some way?
Post Type / Taxonomy Registers
// Products Custom Post Type
register_post_type( 'cpt_products', array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' ),
'all_items' => __( 'View Products' ),
'add_new' => __( 'New Product' ),
'add_new_item' => __( 'New Product' ),
'edit_item' => __( 'Edit Product' ),
'view_item' => __( 'View Product' ),
'search_items' => __( 'Search Products' ),
'no_found' => __( 'No Products Found' ),
'not_found_in_trash' => __( 'No Products in Trash' )
),
'public' => true,
'show_ui' => true,
'query_var' => false,
'show_in_nav_menus' => false,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 20,
'menu_icon' => 'dashicons-cart',
'has_archive' => 'products',
'rewrite' => array( 'slug' => 'product', 'with_front' => false ),
'supports' => array( 'title','editor','thumbnail','page-attributes' )
));
// Testing Taxonomy for Products
register_taxonomy( 'tax_testing', 'cpt_products', array(
'labels' => array(
'name' => __( 'Test' ),
'singular_name' => __( 'Test' ),
'menu_name' => __( 'View Test' ),
'all_items' => __( 'All Test' ),
'edit_item' => __( 'Edit Test' ),
'view_item' => __( 'View Test' ),
'update_item' => __( 'Update Test' ),
'add_new_item' => __( 'New Test' ),
'new_item_name' => __( 'Rename Test' ),
'parent_item' => __( 'Parent Test' ),
'parent_item_colon' => __( 'Parent Test:' ),
'search_items' => __( 'Search Test' ),
'popular_items' => __( 'Popular Test' ),
'seperate_items_with_commas'=> __( 'Separate Test with commas' ),
'add_or_remove_items' => __( 'Add or remove Test' ),
'choose_from_most_used' => __( 'choose from most used Test' ),
'not_found' => __( 'No Test found.' )
),
'show_ui' => true,
'show_admin_column' => true,
'sort' => true,
'rewrite' => array( 'slug' => 'products/test', 'with_front' => false )
));
2 Answers
Register your taxonomies with 'show_ui' => false,
and then add a single meta box to manage them.
function create_book_tax() {
register_taxonomy(
'genre',
'book',
array(
'label' => __( 'Genre' ),
'rewrite' => array( 'slug' => 'genre' ),
'hierarchical' => true,
'show_ui' => false,
)
);
}
Or unhook the boxes from the side panel and put them below the main editor (using a post type and tax form the docs).
add_action(
'add_meta_boxes_book',
function () {
remove_meta_box( 'genrediv', 'book', 'side' );
$tax_name="genre";
$taxonomy = get_taxonomy( $tax_name );
$label = $taxonomy->labels->name;
$tax_meta_box_id = $tax_name . 'div';
add_meta_box(
$tax_meta_box_id,
$label,
$taxonomy->meta_box_cb
);
}
);
A third option is to create your own set of meta box containers and add your boxes to those.
add_action(
'add_meta_boxes_book',
function () {
remove_meta_box( 'genrediv', 'book', 'side' );
}
);
add_action(
'dbx_post_sidebar',
function ($post) {
$tax_name="genre";
$taxonomy = get_taxonomy( $tax_name );
$label = $taxonomy->labels->name;
$tax_meta_box_id = $tax_name . 'div';
add_meta_box(
$tax_meta_box_id,
$label,
$taxonomy->meta_box_cb,
'book',
'mycol1'
);
echo 'my boxes'; //debug
do_meta_boxes('book', 'mycol1', $post);
do_meta_boxes('book', 'mycol2', $post);
do_meta_boxes('book', 'mycol3', $post);
echo 'end my boxes'; //debug
}
);
If you look at the source you will see that the containers you created are surrounded by div
s with the mycol*-sortables
id
. You should be able to use that to create the columns you are after.