Custom Fields
Re-Envisioned
Support MB REST API Custom Post Type by Two Custom Fields via REST API

This topic contains 1 reply, has 2 voices, and was last updated by  Anh Tran 2 months ago.

  • Creator
    Topic
  • #11583
    Resolved
    infinitom
    Participant

    I have a Meta Box added custom post type called ‘house’ and it contains two custom fields (added via Meta Box) that has the ‘street_name’ and ‘city’ for a given house.

    When I query the WP REST API end point for this custom post type, I get all houses and it’s not clear from the documentation how I can pass my custom field preference to the end point so that I only get the houses that match the street_name and city I provide it.

    So my question is, how do I retrieve a house via the API by filtering using the two custom fields?

    I’ve tried to use the WP REST Filter plugin (to restore filter function removed in WP 4.7) and am trying to query the endpoint like this: /house?filter[meta_query][relation]=AND&filter[meta_query][0][key]=street_name&filter[meta_query][0][value]=Evergreen+Terrace&filter[meta_query][1][key]=city&filter&[meta_query][1][value]=Springfield

    Thank you in advance for the help!

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #11585

    Anh Tran
    Keymaster

    Hi,

    In WordPress 4.7, the filter parameter that filter the query parameters was removed. I found a repository on Github that re-add the filter. It’s in the WP-API account on Github, so hopefully, it’s official. Please try it.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.