改变BigCommerce';Wordpress目录

改变BigCommerce';Wordpress目录,wordpress,bigcommerce,Wordpress,Bigcommerce,我想将我的Wordpress博客文章链接到产品类别(以编程方式),因此我使用以下代码更新了bigcommerce\u产品taxonomy类型,使其也出现在post内容类型上 function shop_modify_bc_taxonomy() {   $tax = 'bigcommerce_category';   $bcArgs = get_taxonomy( $tax ); // returns an object   $bcArgs->object_type = array_merg

我想将我的Wordpress博客文章链接到产品类别(以编程方式),因此我使用以下代码更新了
bigcommerce\u产品
taxonomy类型,使其也出现在
post
内容类型上

function shop_modify_bc_taxonomy() {
  $tax = 'bigcommerce_category';
  $bcArgs = get_taxonomy( $tax ); // returns an object
  $bcArgs->object_type = array_merge($bcArgs->object_type, ['post']); // Add 'post'
  register_taxonomy( $tax, $bcArgs->object_type, (array) $bcArgs );
}

// hook it up to 11 so that it overrides the original register_taxonomy function
add_action( 'init', 'shop_modify_bc_taxonomy', 20 );
然而,现在,当产品目录与一个术语相关联时,就会出现帖子

如果我在函数
BigCommerce\Templates\Product\u Archive::get\u posts()
中添加以下行,我的问题就解决了:

private function get_posts( \WP_Query $query ) {
    $cards = [];
    while ( $query->have_posts() ) {
      $query->the_post();
      
      // Add this line
      if (get_post_type() !== 'bigcommerce_product') {  continue;  }

      $product = new Product( get_the_ID() );
      $card    = Product_Card::factory( [
        Product_Card::PRODUCT => $product,
      ] );
      $cards[] = $card->render();
    }
    wp_reset_query();

    return $cards;
  }
但我不知道如何重写这个类。我可以挂接WP\u查询吗?

使用,我们可以在主题的
函数.php
文件中将
post\u类型限制为大型商业产品

function edit_bigcommerce_queries( $query ) {
    if ( ! is_admin() && $query->is_main_query() ) {

        // Is a BigCommerce Category Page
        if ( !empty( $query->query['bigcommerce_category']) {

            $query->set( 'post_type', 'bigcommerce_product');
        }
    }
}
add_action( 'pre_get_posts', 'edit_bigcommerce_queries' );