Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
    
Fantastic, thank you. –  Jukov Jun 16 '11 at 0:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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