0

I'm trying to add a metabox to select a sidebar per page. In order to create the metaboxes I use this class

The construction is fairly easy:

$meta_boxes[] = array(
    'id' => 'sidebars_side',
    'title' => 'Page Sidebar',
    'pages' => array('page', 'post'),
    'context' => 'side',
    'priority' => 'low',

    'fields' => array(
        array(
            'name' => 'Sidebars',
            'id' => 'tst_sidebars',
            'type' => 'select',
            'options' => array(                      
                ARRAY OF SIDEBARS GOES HERE

            ),
            'multiple' => false,

        )
    )
);

But I can't for the love of God to construct the array properly. I checked this post

which is great, but I'm stuck somehow. Any help would be highly appreciated.

1 Answer 1

4

The class you are using accepts value => name pair in the select options array so

foreach ( $GLOBALS['wp_registered_sidebars'] as $sidebar ) { 
    $sidebar_options[$sidebar['id']] = $sidebar['name'];
}

and then you can use $sidebar_options.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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