Custom Fields
Re-Envisioned
Support General Multiple Metabox array names

This topic contains 1 reply, has 2 voices, and was last updated by  Anh Tran 10 months, 3 weeks ago.

  • Creator
    Topic
  • #12308

    Brian 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;
    }
Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #12354

    Anh 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 1 replies (of 1 total)

You must be logged in to reply to this topic.