Open sajjadalis opened 4 years ago
You should check the API Docs for more information. Here
Example Code:
api.get("products", {
order: "asc", // Order sort attribute ascending
orderby: "date" // Order by Date
})
If you want a custom order by value. You should create a filter for rest_event_query
and just pass the corresponding parameters you have added in the params object. You may be interested in WordPress REST API order by meta_value or WordPress REST API post orderby custom value.
I have checked API Docs and there is no option for order by price.
Then i found this topic on WordPress.org. https://wordpress.org/support/topic/how-to-sort-products-by-price-in-rest-api-v3/
So i was wondering how to pass those filter[orderby]=meta_value_num & filter[orderby_meta_key]=_regular_price inside that parameters object.
Thanks for the links. I will look into that.
I don't know whether filter is a valid parameter for the REST API. If you really want to pass those value in the param object.
Example code:
api.get('products', {
"filter[orderby]": "meta_value_num",
"filter[orderby_meta_key]": "_regular_price"
})
Thanks again for the help. I tried this but it's not working. I think filter is not a valid parameter for REST API.
It would be great if there is a way to get it done. Order by Price should be a parameter as it's pretty common way of sorting products on any store site.
CoCart Products API let's you sort products by price @sajjadalis @climba03003
How to get items Ordered by Price?
I found this.
https://www.storeurl.com/wc-api/v3/products?filter[order]=asc&filter[orderby]=meta_value_num&filter[orderby_meta_key]=_regular_price
But not sure how to use filter inside params object:
Thanks