最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Problem with adding programmatically woocommerce product post into category

programmeradmin1浏览0评论

I have problem with adding product to category when I creating this product. I have this code:

$my_post = array(
        'post_type' => 'product',
        'post_title' => 'Drukarka '.$_POST['marka'].' '.$_POST['model'],
        'post_content' => $_POST['opis'],
        'post_status' => 'publish',
        'post_author'   => $current_user->ID,
        'taxonomy' => 'product_cat'

    );

    $post_id = wp_insert_post($my_post);

wp_set_object_terms( $post_id, get_term_by('slug', 'druk-cyfrowy', 'product_cat'), 'product_cat');

Var dump of: wp_set_object_terms( $post_id, get_term_by('slug', 'druk-cyfrowy', 'product_cat'), 'product_cat');

Returns this:

object(WP_Error)#12822 (2) { ["errors"]=> array(1) { ["invalid_taxonomy"]=> array(1) { [0]=> string(26) "Nieprawidłowa taksonomia." } } ["error_data"]=> array(0) { } }

And var dump: of get_term_by('slug', 'druk-cyfrowy', 'product_cat')

Returns false and I don't know why. Please help me

发布评论

评论列表(0)

  1. 暂无评论