微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

高级WooCommerce筛选器:获取查询返回的帖子总数

如何解决高级WooCommerce筛选器:获取查询返回的帖子总数

我创建了一个“产品搜索页面,该页面允许用户使用多重过滤器搜索产品。

这些过滤器为if(digitalRead(64) == 1) { // Zero Crossing off,assign Table Pointer to sample table tbl_ptr = &spl_add_tbl[0]; } else { // Zero Crossing on,assign Table pointer to Zero Crossing Table and set A/D read mapping. tbl_ptr = &zxd_add_tbl[0]; } product_catcustom_taxonomy。我已经使用Vue和axios创建了视图。

过滤器看起来像这样。

price

现在,当发出请求时,我想显示每个类别拥有的号码。

预期输出

Filter

Categories
[x] Category 1  |
[x] Category 2  |
[x] Category 3  |
[x] Category 4  |
[x] Category 5  |

我当前的WP_Query如下:

Filter

Categories
[x] Category 1 (10) |
[x] Category 2 (18) |
[x] Category 3 (12) |
[x] Category 4 (15) |
[x] Category 5 (13) |

注意

  1. 我使用relevanssi_do_query来增强我的结果
  2. 查询中的args的处理方式是:如果查询args,则仅在其中包含值。例如。 $args = array( 'post_type' => 'product','posts_per_page' => $product_per_page,'post_status' => 'publish','offset' => $offset,'tax_query' => array( 'relation' => 'AND',array( 'taxonomy' => 'product_cat','field' => 'id','terms' => $cat_ids,'include_children' => false,'operator' => 'IN' ),'terms' => $selectedcategory,array( 'taxonomy' => 'color','terms' => $selectedcolors,'operator' => 'AND' ),array( 'taxonomy' => 'material','terms' => $selectedmaterials,),'Meta_query' => array( array( 'key' => '_price','value' => $price[0],'compare' => '>=','type' => 'NUMERIC' ),array( 'key' => '_price','value' => $price[1],'compare' => '<=',); $query = new \WP_Query($args); $query->parse_query($args); relevanssi_do_query( $query ); $result_count = $query->found_posts; $products = a(array()); $count = 0; foreach ( $query->posts as $post ) { $buffer = a(array()); $id = $post->ID; $product = Product::getProductData($id); if (!$product) { return; } $product_name = Product::getProductName($product); $product_price = Product::getProductPrice($product); $price = $product->get_price(); $featured_image = Product::getProductFeaturedImage($product); $featured_image_small = Product::getProductFeaturedImageSmall($product); $product_stock = Product::getStockStatus($product); $product_url = Product::getPermalink($product); $product_sizes = Product::getProductSizeStocks($product); $gallery_image = a(Product::getProductgalleryImages($product)); $gallery_image->prepend( array( 'image' => $featured_image,'image_placeholder' => $featured_image_small )); $buffer->appendarrayValues([$id],'id') ->appendarrayValues([$product_name],'name') ->appendarrayValues([$gallery_image],'images') ->appendarrayValues([$product_url],'link') ->appendarrayValues([$product_sizes],'sizes') ->appendarrayValues([$product_stock],'stock_status') ->appendarrayValues([$price],'_price') ->appendarrayValues([$count],'_rindex') ->appendarrayValues([$product_price],'price'); $products->append($buffer->toArray()); $count = $count + 1; } wp_send_json_success( array( 'products' => $products->toArray(),'categories' => $getCategories,'colors' => $getColors,'materials' => $getMaterials,'category' => $category,'parent_cat' => $getParent,'count' => $result_count,'product_per_page' => $product_per_page,) ); die(); $selectedcategory

我不确定应该如何获得每个类别的帖子数量。 ???

谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。