中继器场图像到图库图像

时间:2019-11-13 08:31:48

标签: wordpress advanced-custom-fields

我的网站上有一个提交表单,我尝试将图像从中继器字段中获取为图库图像,这是可行的。我刚刚按照约翰·休布纳的回答在这里: https://support.advancedcustomfields.com/forums/topic/repeater-field-images-to-woocommerce-gallery/

但是,问题是,当我尝试编辑图库图像时,我添加了新图像,但是在图库字段上没有更新新图像。

在此处观看视频:https://jumpshare.com/v/qEm3KlfMejXw2Li7Txfs

// Set Repeater Image as Gallery Images
function my_acf_save_post($post_id) {
    $repeater = 'preview_images_row';
    $subfield = 'preview_images_file';

    // using get_post_meta because that way we're sure to get the image ID
    $count = intval(get_post_meta($post_id, $repeater, true));
    $images = array();
    for ($i=0; $i<$count; $i++) {
        $field = $repeater.'_'.$i.'_'.$subfield;
        $images[] = intval(get_post_meta($post_id, $field, true));
    }
    update_post_meta($post_id, 'preview_images', $images);
}
add_action('acf/save_post', 'my_acf_save_post', 20); // priority of 20 so it runs after ACF

有什么想法要完成吗?

0 个答案:

没有答案