acf-to-rest-api
acf-to-rest-api copied to clipboard
Use plugin as search endpoint
Hi,
thanks for this plugin! I'm trying to implement the following:
I need a global search throughout my site. I'm using ACF in combination with posts and pages. I would now like to search for:
https://domain.com/wp-json/acf/v3/posts?search=foo+bar
and find all posts / pages that have this search term in e.g. their standard wp title OR in various nested acf fields.
e.g. for standard wp post with acf fields
{
"date": "2017-12-05T15:58:04",
"title": "foo bar", // <-- Find it here
...
"acf": {
"heroContent": "foo bar", // <-- OR find it here
"somNode": "Text",
"infoBlocks": [
{
"headline": "Hello",
"text": "<p>Some text. foo bar</p>" //<-- OR here
}
],
...
}
}
I tried several ACF search plugins but none of them worked as expected. Can I achieve such a search behaviour with your plugin and will it be performant?
Hi @benediktdertinger,
Please, read it: https://github.com/airesvsg/acf-to-rest-api/issues/123
Thanks
Hi all,
enabling the ACF: Better Search plugin accomplishes including posts containing a search query in their ACF fields, available via the wp-api at /wp-json/wp/v2/search?search=search_query_string
.
However, this plugin appears to not be adding the acf
key to this endpoint.
@airesvsg do you think this feature could be added? or do you have any other suggestion?
hi again, after further research, the acf
key is available at the search
endpoint, but only if you include the _embed
parameter, eg: /wp-json/wp/v2/search?search=search_query_string&_embed