Skip to main content
1 of 2
Andrea Somovigo
  • 1.6k
  • 1
  • 10
  • 14

First of all it's not clear why getting all products in one go seems to not be an option. You can write your query to get all the products ( maybe in status "publish") something like :

global $wpdb;
$Q="SELECT * FROM ".$wpdb->prefix."posts WHERE post_type = 'product' AND post_status ='publish'";
$completeProductList = $wpdb->get_results($Q);
return new WP_REST_Response($completeProductList, 200);

should work.

Second : without testing your function I think that

if (count($completeProductList < 1)) should be if (count($completeProductList) < 1) your code is counting a boolean instead of a Countable interface, maybe it's not the final solution but this looks like a bug

Andrea Somovigo
  • 1.6k
  • 1
  • 10
  • 14