문제

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.

도움이 되었습니까?

해결책 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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top