WooCommerce-REST-API-Client-Library
WooCommerce-REST-API-Client-Library copied to clipboard
and you can filter products by type of category ?
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
i want to know how filter product by categories ??? if you can have an example tell me
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
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();