【问题标题】:woocommerce wp_set_post_terms only works for adminwoocommerce wp_set_post_terms 仅适用于管理员
【发布时间】:2017-01-29 14:55:29
【问题描述】:

我正在使用 wp_insert_post 添加分类为“product_cat”的 woocommerce 产品。这是我的代码。

首先我添加一个新产品。

$post_id = wp_insert_post( array(
            'post_title' => 'My Title',
            'post_content' => 'This is custom template',
            'post_status' => 'publish',
            'post_type' => "product",
        ) );

在这里,我在该帖子中附加了条款

wp_set_post_terms( $post_id, array(12,13), 'product_cat' );

但是在商店页面上,当我单击添加产品的特定类别时,该产品未显示在该类别中,但在后端(wp 管理员)上,我看到这些条款已附在我的产品中。

【问题讨论】:

    标签: wordpress woocommerce categories taxonomy custom-taxonomy


    【解决方案1】:

    我只是忘记更新“_visibility”

    update_post_meta( $post_id, '_visibility', 'visible' );
    

    现在,一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-29
      • 2020-02-18
      • 2015-03-03
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多