Search code examples
jsonwordpresswordpress-rest-api

Filter custom post type by category in REST API v2 in WordPress


I am creating an Android app using the WP API. I managed to show a custom post type in the REST API which can be viewed in:

http://localhost/wordpress/wp-json/wp/v2/property

Now I want to filter properties by their category, e.g. villa, home, rent, etc. I have tried the following, but it does not work:

http://localhost/wordpress/wp-json/wp/v2/property?filter[category_name]=villa` 
http://localhost/wordpress/wp-json/wp/v2/property?filter[category]=apartment`

Solution

  • I was running into this issue as well with my custom post types.

    You need to query by your custom taxonomy (eg. property_categories, or whatever you named it in your register_taxonomy() function) and then by the term.

    &filter[taxonomy]=property_categories&filter[term]=villa