[NSFW] How to Add ‘Relevance’ Sorting to WooCommerce REST API for Products
-
Hi everyone,
I’m currently working with the WooCommerce REST API to query all products. The endpoint I’m using is
/wp-json/wc/v3/products
. By default, the API allows sorting (orderby
) by several object attributes, such asdate
,id
,include
,title
,slug
,price
,popularity
, andrating
, withdate
being the default sorting method.However, I need to implement a sorting method by
relevance
. Whilerelevance
is a default sorting option within WooCommerce itself, it doesn’t seem to be available by default in the REST API, wheredate
is the preset default.Could anyone guide me on how to add
relevance
as a sorting option to the WooCommerce REST API for product queries? Any advice or pointers to documentation that might help with this would be greatly appreciated.Thank you in advance for your assistance!
The api i am using :
const response = await fetch(
my-website/wp-json/wc/v3/products/?post_type=product&search=searchTerm&page=${page}&per_page=10&orderby=relevance
,{method: ‘GET’,});
- The topic ‘[NSFW] How to Add ‘Relevance’ Sorting to WooCommerce REST API for Products’ is closed to new replies.