Skip to main content
added 57 characters in body
Source Link
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. if you have control on the API Youyou can add a custom endpoint and 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

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

First of all it's not clear why getting all products in one go seems to not be an option if you have control on the API you can add a custom endpoint and 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

Source Link
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