How to ‘clone’ select metabox options with a callback function?

Here is my metabox

      array(
        'id'    => 'all_btns',
        'name'  => 'Button Select',
        'type'  => 'select',
        'options' => array(
            'button'         => 'Button',
            'button_red'     => 'Button Red',
            'button_yellow'  => 'Button Yellow',

        ),             
        'callback' => 'metabox_clone_options',
      ),

I want to clone this options to another metabox array

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Add a simple function in your functions.php file.

function get_button_styles(){
    return array(
        'button'         => 'Button',
        'button_red'     => 'Button Red',
        'button_yellow'  => 'Button Yellow',

    );
}

Use it to get button styles in different metabox fields

array(
    'id'    => 'all_btns',
    'name'  => 'Button Select',
    'type'  => 'select',
    'options' => get_button_styles(),             
    'callback' => 'metabox_clone_options',
),


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x