Include custom fields in WordPress REST API search results

I am working on an application using the WP REST API to display data. I need to be able to search through data entered as a custom field. (I am using Advanced Custom Fields). I have expanded the REST API so that I can grab custom fields using the API. Now I need to include those fields within the searchable data for the post.

I want to search through an HTTP request:

Read More
http://example.com/wp-json/posts?type[]=post&filter[posts_per_page]=5&filter[s]=searchterm

In the above example, searchterm is the term that is being searched for. The above request works, but it will only search within title and content. So if searchterm is within either of those, then the search works but if searchterm is within a custom field then the search does not work.

Is there a way that I can expand the search function of the REST API so that I can search through custom fields?

Thanks!

Related posts

1 comment

Comments are closed.