【发布时间】:2013-05-20 16:00:47
【问题描述】:
好的,我会尝试以一种不会让每个人都对我的困惑感到困惑的方式提出这个问题
我正在尝试为 WooCommerce 制作前端表单,以便客户可以从前端制作产品。 到目前为止,我想要实现的所有其他部分都在工作,即。标题、内容和价格 所有张贴在正确的帖子类型。但无法将其发布到产品类别
WooCommerce 类别是一个名为 product_cat 的自定义分类法
product_cat 子项是术语,我有三个 --> Base、Designs 和 User Designs
我希望此表单中的所有帖子都自动位于用户设计下。这就是我现在拥有的
$post_information = array(
'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
'post_content' => esc_attr(strip_tags($_POST['postContent'])),
'post_type' => 'product',
'post_status' => 'publish',
);
$post_id = wp_insert_post($post_information);
update_post_meta( $post_id, '_regular_price', strip_tags($_POST['_regular_price'] ) ) ;
if($post_id)
{
wp_redirect(home_url());
exit;
}
};
我尝试了许多变体来设置术语,例如
wp_set_object_terms($post_id, 'designs', 'product_cat', false);
wp_set_post_terms($post_id, 'designs', 'product_cat', false);
wp_set_object_terms($post_id, $designs ,'product_cat');
wp_set_post_terms( $post_id, $designs, 'product_cat', true );
wp_set_object_terms($post_id, $base, 'product_cat');
不行,我知道我错过了一些东西,但我不知道是什么。我一直盯着屏幕看很久了,眼睛都在交叉,
任何帮助将不胜感激提前感谢
【问题讨论】:
标签: php wordpress frontend woocommerce