【问题标题】:Woocommerce, update ACF field and short description with SQLWoocommerce,使用 SQL 更新 ACF 字段和简短描述
【发布时间】:2021-01-21 13:36:34
【问题描述】:

我有一个 WooCommerce 设置,我目前需要做两件事。第一个是将当前在 post.excerpt 字段中的数据移动到我专门为此目的创建的 ACF 字段,而第二个是用新数据更新 post.excerpt 字段。所有产品数据都在 SQL-Server Express 中,因为产品数据来自另一个网站,我们用 WooCommerce 替换了该网站。我导出了所有带有基本信息(如产品 ID、SKU、标题和 Post_Content)的 Woocommerce 产品,并在 SQL-Server 中编写了一个查询以将两者匹配在一起。这已作为平面文件导出并导入 MySQL。现在我编写了一个查询来更新 post.excerpt 字段,但我找不到在同一个查询(或另一个查询)中更新 ACF 字段的方法。

set 
'wp.posts'.'post.excerpt' = 'updatelist'.'excerpt'
From 'updatelist'
where
'wp_posts'.'ID' = 'updatelist'.'product_id'

有人可以帮忙吗?请不要建议导入 CSV 文件。有 180,000 种产品,使用 csv,大约完成了 10%,到目前为止,已经花费了 24 小时。

【问题讨论】:

    标签: sql wordpress woocommerce


    【解决方案1】:

    要更新 ACF 字段,首先我通常会准备一组 ACF 字段的键值对来循环并更新它们:

    # first prepare your array of ACF fields you need to update
     
    acf_fields = [
        'field_5f70*********' => 'product_name',
        'field_5f80*********' => 'product_color',
        'field_5f90*********' => 'product_price'
    ];
    
    # to find the key values for your own ACF fields, just go to admin dashboard under custom fields, select your group of ACF fields and then on the "Edit Field Group" you see those keys. If you don't see them, choose "screen options" and select "fields keys".
    
    # Now we're going to loop over them and update each field  
    
    foreach(acf_fields as $key => $name){
        update_field(a, b, c);
    # a = $key
    # b = value to be updated which comes from your old list (from querying your list)
    # c = which post it belongs to (custom query for your custom post type that contains ACF fields)
    };
    

    这就是我更新我的 ACF 字段的方式,还有其他使用 Wordpress REST API 的方法。

    【讨论】:

      猜你喜欢
      • 2021-02-28
      • 2020-08-28
      • 1970-01-01
      • 2022-11-30
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 2021-04-24
      • 2017-02-09
      相关资源
      最近更新 更多