带有自定义字段的自定义 post 中的 wordpress wp_include_post()

wordpress wp_include_post() in custom post with coustom field

我是 WordPress 新手,我的英语不是很好。我正在使用 Custom Post Type UI plugin to create a post type Product and Advanced Custom Fields 插件来创建一些自定义字段,例如地址。现在,我正在阅读包含 3000 种产品的 XML 文件(标题、描述、价格、品牌等),并将所有这些保存在我的自定义数据库中。在读取并将其保存在数据库中时,我想创建 post 类产品,其中名称是标题,slug 是标题(我可以按品牌创建类别还是从其他自定义字段创建类别?)描述等。 wp_insert_post() 如何在自定义字段中插入 $variable?我想要类似

的东西
$my_post = array(
  'post_title'    => $row['product_name'],
  'post_content'  => $row['description'],
  'post_status'   => 'publish',
  'post_name'      => $row['product_name'],
  'post_author'   => 1,
  'post_type'     => 'product',
  'custom_field_brand'         => $row['brand'], 
  'custom_field_price'         => $row['price']
);

wp_insert_post( $my_post );

高级自定义字段保存 post 元数据的方式略有不同。您在这里要做的是在

之后的 wp_insert_post 中包含 post 元数据
wp_insert_post( $my_post );

returns 创建的 post 的 ID。

使用带有 acf 函数的 Post ID update_field() 像这样更新 post meta

update_field( custom_field, custom_field_data, $post_id );