0

For a custom plugin I want a full list of all products we have in WooCommerce. So, I found this code, but it shows only 10 results, instead of all products.

$loop = new WP_Query( array('post_type' => 'product', 'post_per_page' => -1));

What is the right loop to get all products?

0

1 Answer 1

1

You can try this:

$options = array('post_type'.    => 'product', 
                 'post_per_page' => -1,
                 'nopaging' => true, )
$loop    = new WP_Query( $options );

This adds 'nopaging' => true,. See Class_Reference/WP_Query#Pagination_Parameters for more info

3
  • Yeah! Simpel trick and does his job!
    – NVO
    May 22, 2017 at 8:01
  • @NVO Great to hear
    – xvilo
    May 22, 2017 at 13:21
  • And thanks @toscho, I didn't check my markup!
    – xvilo
    May 22, 2017 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.