Meta box io oemed返回列表而不是数组

时间:2017-12-31 作者:Phaidonas Gialis

我创建了一个嵌入克隆的元框:

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\' );
它工作得很好,只是我无法用foreach获取视频

我有一个vimeo和一个youtube视频。

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


    foreach ( $btsvideoembeds as $btsvideoembed ) {
    echo \'<div>\';
     echo $btsvideoembed;
         echo \'</div>\';
     }
它返回的字符串不是数组

2 个回复
最合适的回答,由SO网友:Dev 整理而成

您也可以这样编码:

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

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

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

SO网友:Phaidonas Gialis

我这样更改了代码,现在可以工作了:

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


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

结束

相关推荐

WP自定义字段Metabox消失-ACF插件问题

所有帖子(包括CPT)上的WP自定义字段元框消失,帖子屏幕选项中的复选框也消失了。仅当高级自定义字段被激活时,才会发生这种情况。我的任何ACF字段组都不会隐藏自定义字段元盒,停用所有字段组也不会解决此问题。如何在帖子上显示自定义字段元框?