Question

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

 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 plugins\meta-box\inc\fields\select.php on line 132

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

Was it helpful?

Solution 2

See where you declare array

it's may be out of function

or inside of other function

try to declare it in function or make array global

OTHER TIPS

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.

Its not logical error, its from your syntax. Check your syntax from foreach.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top