【发布时间】:2014-06-02 08:58:37
【问题描述】:
我正在构建一个表单,供用户使用 wp_insert_post 和 update_post_meta 通过我的网站前端创建产品。
在尝试设置产品类别和标签时出现问题。在这方面,Woocommerce 似乎没有使用标准的 Wordpress 分类法。有人对此有经验吗?似乎 Woocommerce 在某些地方使用product_tags。是否有类似于 Wordpress 的功能来创建它们?
下面是我正在做的事情。谢谢!
$post = array(
'ID' => '',
'post_content' => $_POST['post_content'],
'post_title' => $_POST['post_title'],
'post_status' => 'draft',
'post_type' => 'product',
'post_author' => $user_id,
);
$newListing = wp_insert_post($post, $wp_error);
//SET META
update_post_meta($newListing, '_stock_status', 'instock', true);
update_post_meta($newListing, '_visibility', 'visible', true);
update_post_meta($newListing, '_price', $_POST['_regular_price'], true);
//SET CATEGORIES - **NOT WORKING**
wp_set_post_categories($newListing, $categories);
//SET THE TAGS **NOT WORKING**
wp_set_post_tags($newListing, $tags, true);
【问题讨论】:
标签: php wordpress tags woocommerce categories