为什么没有显示产品?
Why are the products not shown?
<?php
add_action('wp_ajax_nopriv_filter', 'filter_ajax');
add_action('wp_ajax_filter', 'filter_ajax');
function filter_ajax(){
$category = $_POST['category'];
$args = array(
'taxonomy' => 'product_cat',
'post_type'=>'product',
'posts_per_page' => -1,
);
if(isset($category)) {
$args['category__in'] = array($category);
}
类目id送达了,但不清楚为什么选择的类目商品没有显示
$loop = new WP_Query($args);
if($loop->have_posts()):
while ( $loop->have_posts() ) : $loop->the_post(); global $product;
?>
<ul class="list-group list-group-flush list-group-products">
<li class="list-group-item select-blue-essence">
<div class="row in-list-text">
<div class="col-4 text-center font-poppins js-filter">
<span class="fw-bold"><?php the_title();?></span><br>
<span><?php the_content();?></span>
</div>
<div class="col-4 price-tag font-poppins fw-bold"><?php echo $product->get_price_html(); ?>
<?php woocommerce_template_loop_add_to_cart(); ?></div>
</div>
</li>
</ul>
</div>
<?php endwhile;
endif;
wp_reset_postdata();
die();
} ?>
$category = isset($_POST['category']) :?array(absint($_POST['category'])) : array();
$args = array(
'posts_per_page' => -1,
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $category
)
)
);
$loop = new WP_Query($args);
试试这个 - 类别 ID 应该是整数
<?php
add_action('wp_ajax_nopriv_filter', 'filter_ajax');
add_action('wp_ajax_filter', 'filter_ajax');
function filter_ajax(){
$category = $_POST['category'];
$args = array(
'taxonomy' => 'product_cat',
'post_type'=>'product',
'posts_per_page' => -1,
);
if(isset($category)) {
$args['category__in'] = array($category);
}
类目id送达了,但不清楚为什么选择的类目商品没有显示
$loop = new WP_Query($args);
if($loop->have_posts()):
while ( $loop->have_posts() ) : $loop->the_post(); global $product;
?>
<ul class="list-group list-group-flush list-group-products">
<li class="list-group-item select-blue-essence">
<div class="row in-list-text">
<div class="col-4 text-center font-poppins js-filter">
<span class="fw-bold"><?php the_title();?></span><br>
<span><?php the_content();?></span>
</div>
<div class="col-4 price-tag font-poppins fw-bold"><?php echo $product->get_price_html(); ?>
<?php woocommerce_template_loop_add_to_cart(); ?></div>
</div>
</li>
</ul>
</div>
<?php endwhile;
endif;
wp_reset_postdata();
die();
} ?>
$category = isset($_POST['category']) :?array(absint($_POST['category'])) : array();
$args = array(
'posts_per_page' => -1,
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $category
)
)
);
$loop = new WP_Query($args);
试试这个 - 类别 ID 应该是整数