airesvsg / acf-to-rest-api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API
https://wordpress.org/plugins/acf-to-rest-api/
1.33k stars 110 forks source link

Filter products categories by ACF field #397

Open fredoche1810 opened 2 years ago

fredoche1810 commented 2 years ago

Hello, I try to filter the list of categories of the products received by the rest api. I add 'myfield' as ACF field. With the plugin ACF-to-rest-api I can see the field in the rest api result under acf : {}

This url returns all the categories. https://mywebsite/wp-json/wc/v3/products/categories/

I want to be able to filter a custom field added by ACF https://mywebsite/wp-json/wc/v3/products/categories/?myfield=testvalue

Could someone help me ?

I suppose there is a filter or an action to add in the functions.php file but everything I tried returned all the categories without any filter.

What’s also strange, for the products, I can see in the rest api result the metadata with the values added by ACF For the category, the metadata aren’t visible. In the database the values are stored in termmeta for the categories and in postmeta for the products. If I’m right, the product is a post and the category is a taxonomy.

Thanks in advance,