Meta box io oembed returns list not array

i have created a meta box oembed with clone:

function media( $meta_boxes ) {
    $prefix = '';

    $meta_boxes[] = array(
        'id' => 'media_1',
        'title' => esc_html__( 'Media', 'media' ),
        'post_types' => array( 'post','personal_projects' ),
        'context' => 'advanced',
        'priority' => 'high',
        'autosave' => true,
        'fields' => array(
            array(
                'id' => $prefix . 'image_advanced_2',
                'type' => 'image_advanced',
                'name' => esc_html__( 'Gallery', 'media' ),
            ),
            array(
                'id' => $prefix . 'video_1',
                'type' => 'video',
                'name' => esc_html__( 'Video', 'media' ),
            ),
            array(
                'id' => $prefix . 'oembed_1',
                'type'=> 'oembed',
                'name' => esc_html__( 'Embed Video', 'media' ),

                'clone' => true,
                'add_button' => esc_html__( 'Add video', 'media' ),
                'sort_clone' => true,
            ),
            array(
    'id' => $prefix . 'url_1',
    'type' => 'url',
    'name' => esc_html__( 'URL', 'media' ),
    'clone' => true,
),


        ),
    );

    return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'media' );

it works very good except i can not get the videos with foreach

i have a vimeo and a youtube video.

$btsvideoembeds = array();
$btsvideoembeds = rwmb_meta ( 'oembed_1', array( 'type' => 'oembed' ) );


    foreach ( $btsvideoembeds as $btsvideoembed ) {
    echo '<div>';
     echo $btsvideoembed;
         echo '</div>';
     }

it return string not array

2 Answers
2

You could also code it like this :

$btsvideoembeds = rwmb_get_value( 'oembed_1', array( 'type' => 'oembed' ) );

foreach ( (array) $btsvideoembeds as $btsvideoembed ) {

printf('%s', wp_oembed_get( $btsvideoembed ) );

Leave a Comment