0

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

3
  • Don't know if it's a good solution or not, but I created a helper function (let's say get_button_styles()) in functions.php file, which returns an array with style options. Than you can just call this function as many times as you want. 'options' => get_buttons_styles() – anton Jun 1 at 16:34
  • Thank you very much, it worked, I was thinking about a solution for hours, it helped me a lot – Yem Jun 1 at 17:26
  • Glad it helped you. I will add a comment as an answer also. – anton Jun 1 at 17:43
0

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',
),

Not the answer you're looking for? Browse other questions tagged or ask your own question.