0

I have a code:

$products_query_params = array(
    'post_type' => 'product',
    'product_cat' => 18,
);

return new WP_Query($products_query_params);

I need it to get products. But it works fine only if I write it directly in function.php - function $product->have_posts() returns true in this case in admin area.

But if I try to create a shortcode and display the same thing on the front end of the site, then $product->have_posts() returns false.

I think I need to add some parameter to $products_query_params, but I don't know which one.

2
  • Is your code in a function? What is $product? What's your shortcode code? Nov 18, 2023 at 14:05
  • @JacobPeattie in a functions.php – pastebin.com/awTdqXzE This shortcode in index.php – <?php echo do_shortcode('[bags_products]'); ?>
    – Wembley
    Nov 18, 2023 at 15:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.