wordpress - 我有一组 CMB2 字段,我正在将 url 元导入到,它适用于单个字段,但不适用于分组
问题描述
我有一个需要添加 url 元数据的字段,到目前为止,我有这个允许我将元数据添加到单个字段。
add_action( 'cvm_post_insert', 'add_extra_meta_data', 40, 3 );
函数 add_extra_meta_data( $post_id, $video, $theme_import ){
if ( get_post_status( $post_id ) == 'draft' ) {
$url = cvm_video_url($video['video_id']);
if($url){
update_post_meta($post_id, 'exercise_gallery_embed', $url);
}
}
}
但是当我使用分组字段时,输入字段名称看起来更像这样,因为它正在堆叠 id
add_action( 'cvm_post_insert', 'add_extra_meta_data', 40, 3 );
函数 add_extra_meta_data( $post_id, $video, $theme_import ){
if ( get_post_status( $post_id ) == 'draft' ) {
$url = cvm_video_url($video['video_id']);
if($url){
update_post_meta($post_id, 'exercise_gallery[0][exercise_gallery_embed]', $url);
}
}
}
虽然我可以在自定义字段中看到数据,但它不会将 url 添加到元框,欢迎任何帮助或指针。以下是正在使用的字段组。
// Repeatable group.
$gallery_group = $cmb->add_field(
array(
'id' => $this->slug . '_gallery',
'type' => 'group',
'options' => array(
'group_title' => __( 'Gallery', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number
'add_button' => __( 'Add Item', 'lsx-health-plan' ),
'remove_button' => __( 'Remove Item', 'lsx-health-plan' ),
'sortable' => true,
),
'desc' => __( 'Upload only one image, video or gif per gallery group, each group will only display 1 item.', 'lsx-health-plan' ),
'classes' => 'lsx-admin-row',
)
);
// Title.
$cmb->add_group_field(
$gallery_group,
array(
'name' => __( 'Image', 'lsx-health-plan' ),
'id' => $this->slug . '_gallery_image',
'type' => 'file',
'text' => array(
'add_upload_file_text' => __( 'Add File', 'lsx-health-plan' ),
),
'desc' => __( 'Upload an image a minimum of 800px x 600px in size.', 'lsx-health-plan' ),
'query_args' => array(
'type' => array(
'image/gif',
'image/jpeg',
'image/png',
),
),
'preview_size' => 'lsx-thumbnail-wide',
'classes' => 'lsx-field-col lsx-field-col-80',
)
);
// Title.
$cmb->add_group_field(
$gallery_group,
array(
'name' => __( 'oEmbed', 'lsx-health-plan' ),
'id' => $this->slug . '_gallery_embed',
'type' => 'text',
'desc' => __( 'Drop in the embed url for your video from YouTube, Vimeo or DailyMotion, e.g: "https://www.youtube.com/watch?v=9xwazD5SyVg". A full list of supports formats can be found at <a href="https://make.wordpress.org/support/user-manual/content/media/adding-media-to-your-pages-and-posts/embedding-media-from-other-sites/">WordPress</a>', 'lsx-health-plan' ),
'classes' => 'test-apply-form lsx-field-col lsx-field-col-50',
)
);
解决方案
推荐阅读
- c++ - 退货不能转换
- python - 有没有办法用 django 显示 jupyter 笔记本
- sql-server - LocalDb 上“PROVIDER”附近的语法不正确
- xpath - Xpath:如何在句子中分别选择第一个和第二个数字
- sql - 按包含/排除/空日期范围限制记录
- r - R dplyr:使用前一行值和函数计算行值
- c++ - 获取“错误:无法转换 'std::__cxx11::string* {aka std::__cxx11::basic_string
*}' 到 'const char*' 错误,同时将路径作为参数传递 - python - 使用 etree 在 python 中解析 XML
- python - python blurwuzzy 模糊匹配 - 排除术语
- python-3.x - “从 pyoptsparse 导入优化”不是 pyoptsparse_driver.py 中的有效参考