我正在使用CMB2 设置元框的重复字段,但我找不到任何关于如何在前端显示重复oEmbed字段的文档。使用下面的代码,我让metabox在后端工作:
add_action( \'cmb2_init\', \'cmb2_register_repeatable_media_resources_metabox\' );
function cmb2_register_repeatable_media_resources_metabox() {
$prefix = \'_cmb_r_\';
$cmb_group = new_cmb2_box( array(
\'id\' => $prefix . \'resources_media_metabox\',
\'title\' => __( \'Media Resources\', \'cmb2\' ),
\'object_types\' => array( \'resources\', ),
) );
// Parent
$group_field_id = $cmb_group->add_field( array(
\'id\' => $prefix . \'resources_media_group\',
\'type\' => \'group\',
\'options\' => array(
\'group_title\' => __( \'Entry {#}\', \'cmb2\' ),
\'add_button\' => __( \'Add Another Entry\', \'cmb2\' ),
\'remove_button\' => __( \'Remove Entry\', \'cmb2\' ),
\'sortable\' => true, // beta
),
) );
// Media Resource Title
$cmb_group->add_group_field( $group_field_id, array(
\'name\' => __( \'Media Resource Title\', \'cmb2\' ),
\'id\' => \'media_resource_title\',
\'type\' => \'text\',
) );
// Media Resource
$cmb_group->add_group_field( $group_field_id, array(
\'name\' => __( \'oEmbed\', \'cmb2\' ),
\'id\' => $prefix . \'media_embed\',
\'type\' => \'oembed\',
) );
}
我可以在前端显示标题,但不能显示嵌入的URL?
<?php $resources_media_group = get_post_meta( get_the_ID(), \'_cmb_r_resources_media_group\', true ); ?>
<div>
<ul>
<?php foreach ( $resources_media_group as $value ) { ?>
<li>
<h3><?php echo $value[\'media_resource_title\'] ?></h3>
<?php echo $value[\'media_embed\'] ?>
</li>
<?php } ?>
</ul>
</div>