acf-to-rest-api icon indicating copy to clipboard operation
acf-to-rest-api copied to clipboard

Use plugin as search endpoint

Open benediktdertinger opened this issue 6 years ago • 3 comments

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?

benediktdertinger avatar May 23 '18 08:05 benediktdertinger

Hi @benediktdertinger,

Please, read it: https://github.com/airesvsg/acf-to-rest-api/issues/123

Thanks

airesvsg avatar Jun 04 '18 22:06 airesvsg

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?

ryanrain avatar Jan 30 '20 19:01 ryanrain

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

ryanrain avatar Feb 01 '20 16:02 ryanrain