John Davidson

php - Why are the products not shown?

0 comments
Message:


<?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);
}

The category id is delivered, but it is not clear to me why the products of this selected category are not displayed


             $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();

} ?>


My Answer:
There could be several reasons why the products are not being shown. Some possible reasons include:

1. The products may not be properly added to the database or the database connection may be incorrect.
2. There may be an issue with the code that retrieves and displays the products on the website.
3. The products may be out of stock or have been set to not display on the website.
4. There could be a problem with the server or hosting environment that is preventing the products from being displayed.
5. There may be a caching issue that is preventing the products from being updated or displayed correctly.

To troubleshoot the issue, you can check the database connection, review the code that retrieves and displays the products, check the product settings in the backend of the website, and ensure that there are no server or caching issues causing the problem.

Rate this post

5 of 5 based on 1756 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us