Meta box tabs in a custom post type
- This topic has 1 reply, 2 voices, and was last updated 3 years ago by
Long Nguyen.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
May 14, 2022 at 1:50 AM #36018
Philippe Eysseric
ParticipantIs it possible to insert meta box tabs in a specific content post type.
I've been looking in the example :add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) { // 1st Meta Box $meta_boxes[] = array( 'title' => 'MB Tabs Demo', // List of tabs, in one of the following formats: // 1) key => label // 2) key => array( 'label' => Tab label, 'icon' => Tab icon ) 'tabs' => array( 'contact' => array( 'label' => 'Contact', 'icon' => 'dashicons-email', // Dashicon ), 'social' => array( 'label' => 'Social Media', 'icon' => 'dashicons-share', // Dashicon ), 'note' => array( 'label' => 'Note', 'icon' => 'https://i.imgur.com/nJtag1q.png', // Custom icon, using image ), ), // Tab style: 'default', 'box' or 'left'. Optional 'tab_style' => 'default', // Show meta box wrapper around tabs? true (default) or false. Optional 'tab_wrapper' => true, 'fields' => array( array( 'name' => 'Name', 'id' => 'name', 'type' => 'text', // Which tab this field belongs to? Put tab key here 'tab' => 'contact', ), array( 'name' => 'Email', 'id' => 'email', 'type' => 'email', 'tab' => 'contact', ), array( 'name' => 'Facebook', 'id' => 'facebook', 'type' => 'text', 'tab' => 'social', ), array( 'name' => 'Note', 'id' => 'note', 'type' => 'textarea', 'tab' => 'note', ), ), );
This will work in post if added to functions.php ... but if we try to use it in a custom post type the metabox will appear but the fields will not.
Any help would be appreciated.
May 14, 2022 at 6:27 PM #36022Long Nguyen
ModeratorHi Philippe,
You need to add the meta box ID and post type settings when registering the meta box. For example:
add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) { $meta_boxes[] = [ 'title' => 'Event details', 'post_types' => 'event', //here 'id' => 'my-meta-box-id', //here 'fields' => [ ... ], ]; return $meta_boxes; } );
Read more on the documentation https://docs.metabox.io/creating-fields-with-code/
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.