WooCommerce-REST-API-Client-Library icon indicating copy to clipboard operation
WooCommerce-REST-API-Client-Library copied to clipboard

How can I fetch only parent product categories ?

Open amitturboc opened this issue 9 years ago • 2 comments

I am using $client->products->get_categories();.. It give me all categories. But I want only parent product categories.

amitturboc avatar Jun 07 '16 09:06 amitturboc

Simply put all the values into a variable and loop through looking for parent = '0'

$categories = $client->products->get_categories();

$parentcats = array();
foreach($categories as $category) {
  if($category['parent'] == 0) {
    $parentcats[] = $category; 
  }
}

print_r($parentcats);

dyluck07 avatar Jul 08 '16 18:07 dyluck07

Yes you are correct. I know.it is possible in client end. I want filter from server end..not in client end....

amitturboc avatar Jul 11 '16 04:07 amitturboc