meta box plugin use php array as select options?

I have PHP array

$my_array=Array
(
  [0] => standard
  [1] =>  aside
  [2] =>  image
  [3] =>  gallery
  [4] =>  video
  [5] =>  status
  [6] =>  quote
  [7] =>  link
  [8] =>  chat
  [9] =>  audio
 );

I want to use it as meta-box plugin select options

Read More
 array(
    'name' =>  __( 'Select', 'rwmb' ),
    'id'   => "{$prefix}page_icon",
    'type'     => 'select',
    'options'  => $my_array,
    'multiple'    => false,
    'placeholder' => __( 'Select an Item', 'rwmb' ),
 ),

It give me error.

Warning: Invalid argument supplied for foreach() in pluginsmeta-boxincfieldsselect.php on line 132

how I can use it?
any solution accepted.
thanks.

Related posts

Leave a Reply

3 comments

  1. You could try this:

        // SELECT BOX
        array(
            'name'     => __( 'Select', 'rwmb' ),
            'id'       => "{$prefix}select",
            'type'     => 'select',
            // Array of 'value' => 'Label' pairs for select box
            'options'  => array(
                'standard' => __( 'Standard', 'rwmb' ),
                'aside'    => __( 'Aside',    'rwmb' ),
                'gallery'  => __( 'Gallery',  'rwmb' ),
                'image'    => __( 'image',    'rwmb' ),
                'aside'    => __( 'Aside',    'rwmb' ),
                'video'    => __( 'Video',    'rwmb' ),
                'status'   => __( 'Status',   'rwmb' ),
                'quote'    => __( 'Quote',    'rwmb' ),
                'link'     => __( 'Link',     'rwmb' ),
                'chat'     => __( 'Chat',     'rwmb' ),
                'audio'    => __( 'Audio',    'rwmb' ),
            ),
            // Select multiple values, optional. Default is false.
            'multiple'    => FALSE,
            'std'         => 'standard',
            'placeholder' => __( 'Select an Item', 'rwmb' ),
        ),
    

    Your array is not written in the correct PHP syntax, so that’s most likely the error you’re receiving.

    There’s a nice explanation here in the PHP manual on how to construct arrays .

    But you should also consider the add_theme_support() advice suggested in the comments, if you’re setting up multiple post formats.

    It will give a radio box like this one.

    Post formats

    See for example this description.