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

and you can filter products by type of category ?

Open eros2187 opened this issue 8 years ago • 3 comments

hi I'm using this library to my project I want to know if and can filter The list of products by category? that syntax must utilize ?? thank you

you can have an example? thank you

eros2187 avatar Aug 08 '16 11:08 eros2187

i want to know how filter product by categories ??? if you can have an example tell me

vsinghp avatar Aug 27 '16 18:08 vsinghp

when you receive an array of products from api woocommerce how can I do to filter the products according to a category? how you should write in php

exsample

products->get(filter[category]' => $cat) ); ?>

it's possible?? you can do something like the current api permit? otherwise how can I do to implement this feature? it would be helpful certainly

Can you explain how?

thanks for your time giuseppe

eros2187 avatar Aug 27 '16 19:08 eros2187

Unfortunately this is not currently possible. WP Query does not facilitate orderby category.

The approach I would suggest would be to pull each category separately loop through them and then sort by title ASC but this very heavy on the server depending on store size etc

$categories = get_categories( array ('orderby' => 'name', 'order' => 'asc' ) );

foreach ($categories as $category){

echo "Category is: $category->name
";

$catPosts = new WP_Query( array ( 'category_name' => $category->slug, 'orderby' => 'title' ) );

if ( $catPosts->have_posts() ){

   while ( $catPost->have_posts() ){
      $catPost->the_post();
      echo "<a href='the_permalink()'>the_title()</a>";
   }

   echo "<p><a href='/category/$category->slug'>More...</a></p>";

}//end if

} //end foreach

wp_reset_postdata();

jaythegeek avatar Sep 11 '16 14:09 jaythegeek