wp query – Products are displayed only in the admin area


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.

Wembley 4 months 2023-11-18T04:20:24-05:00 0 Answers 0 views 0

Leave an answer