如何在ACF自定义字段中发布而不是获取ACF字段的数组

问题描述

首先很抱歉,如果这是重复一个线程,我尝试了无休止的查找。 我在网站上使用Woo-commerce和Dokan多供应商插件。我正在尝试在一个字段中添加产品缩略图和画廊图像。默认情况下,woo-commerce和dokan在 post_meta 表中将特色图片发布为 _thumbnail_id ,并将其余图片发布为 _product_image_gallery

我已经在 post_meta 表中将ACF字段设置为 product_gallery 。 而不是我自己从后端填充字段,我认为这可以由供应商通过 add_action “保存”或更新其产品到dokan的挂钩 dokan_product_updated 中来完成我的主题功能文件。

如果我一次只使用一个变量结果,但又不希望将它们作为数组发布到一个元值中,则该方法有效。

任何帮助都将不胜感激,因为我提到我找不到解决方法。预先感谢。

    add_action( 'dokan_product_updated','_product_thumbnail_to_acf_product_gallery_field',20);

     function _product_thumbnail_to_acf_product_gallery_field ($post_id){
    
      $featuredimage = get_field ('_thumbnail_id',$post_id);   //thumbnail
      $galleryimages = get_field ('_product_image_gallery',$post_id);  //rest of the images
      $galleryimages_ids_string = implode(',',wp_list_pluck($galleryimages,['ID']));

$update_gallery = update_post_meta($post_id,'product_gallery',$galleryimages); //update gallery

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)