Multiple Metabox array names

Support General Multiple Metabox array names

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #12308
    Brian ThurberBrian Thurber
    Participant

    Is it possible to setup 2 metaboxes with different array names? For instance:
    $meta_boxes_announcements[] = array() and $meta_boxes[] = array()

    add_filter( 'rwmb_meta_boxes', 'announcements_register_meta_boxes' );
    function announcements_register_meta_boxes( $meta_boxes ) {
        $prefix = 'announcements_';
        $meta_boxes_announcements[] = array(
            'id'         => 'announcements',
            'title'      => 'Announcements Meta',
            'post_types' => 'announcements',
    
            'fields' => array(
                // DATE
                array(
                    'name'       => __( 'Event Date - If nothing is entered here, the post publish date will be used', 'announcements_' ),
                    'id'         => "{$prefix}display_date",
                    'type'       => 'date',
                ),
    
            )
        );
        return $meta_boxes_announcements;
    }
    
    add_filter( 'rwmb_meta_boxes', 'register_meta_boxes' );
    function register_meta_boxes( $meta_boxes ) {
        $prefix = 'uu_';
        $meta_boxes[] = array(
            'id'         => 'uu_metabox',
            'title'      => 'My Metabox',
            'post_types' => 'post',
    
            'fields' => array(
                // DATE
                array(
                    'name'       => __( 'Event Date - If nothing is entered here, the post publish date will be used', 'announcements_' ),
                    'id'         => "{$prefix}display_date",
                    'type'       => 'date',
                ),
    
            )
        );
        return $meta_boxes;
    }
    #12354
    Anh TranAnh Tran
    Keymaster

    Hi Nakaiya,

    Yes, of course. But in the callback function of the rwmb_meta_boxes filter, please just use the variable $meta_boxes. It's an array of meta boxes. Each meta box has a different title.

    So, your code can be modified to this:

    add_filter( 'rwmb_meta_boxes', 'announcements_register_meta_boxes' );
    function announcements_register_meta_boxes( $meta_boxes ) {
        $prefix = 'announcements_';
        $meta_boxes[] = array(
            'id'         => 'announcements',
            'title'      => 'Announcements Meta',
            'post_types' => 'announcements',
    
            'fields' => array(
                // DATE
                array(
                    'name'       => __( 'Event Date - If nothing is entered here, the post publish date will be used', 'announcements_' ),
                    'id'         => "{$prefix}display_date",
                    'type'       => 'date',
                ),
    
            )
        );
        return $meta_boxes;
    }
    
    add_filter( 'rwmb_meta_boxes', 'register_meta_boxes' );
    function register_meta_boxes( $meta_boxes ) {
        $prefix = 'uu_';
        $meta_boxes[] = array(
            'id'         => 'uu_metabox',
            'title'      => 'My Metabox',
            'post_types' => 'post',
    
            'fields' => array(
                // DATE
                array(
                    'name'       => __( 'Event Date - If nothing is entered here, the post publish date will be used', 'announcements_' ),
                    'id'         => "{$prefix}display_date",
                    'type'       => 'date',
                ),
    
            )
        );
        return $meta_boxes;
    }
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.