Forums › Forums › Search & Filter Pro › How to combine two search result sets, OR search an ACF repeater field
Tagged: acf, advanced custom fields, repeater
- This topic has 2 replies, 2 voices, and was last updated 6 years, 6 months ago by Anonymous.
-
Anonymous(Private) May 7, 2018 at 5:46 pm #176166
Getting the plugin to use the text field to search in an ACF repeater field is turning out to be a real challenge.
Right now I have a search form set up with an regular search text field and three taxonomy select lists. It works well finding results based on standard WP fields like title or content, but I can’t figure out if there is a way to get it to search through an ACF repeater field.
In the posts, I have an ACF repeater field called “Authors/Speakers”, which allows you to choose posts from another post type called “person”. The person post type is essentially our list of employees, so this allows us to choose multiple people on any given post, who are then displayed as authors or speakers.
The idea is for when someone searches for “Joe Smith”, then the results would include posts where Joe Smith was selected in the Authors/Speakers field. Unfortunately the plugin only searches through the non-ACF fields like title or content, so it never finds posts with Joe Smith.
I have tried using the ‘sf_edit_query_args’ filter, but I can’t enter the correct query args at this point in the query. I think what would have to happen is I need to do two queries: one is whatever the plugin queries, and another manual WP_Query to search for the author/speakers. Then merge the resulting post arrays. But then the problem is that I can’t figure out how to get the plugin’s result array.
How do I get the plugin to use the search field to also search through an ACF repeater field?
Trevor(Private) May 8, 2018 at 9:52 am #176287I would answer the last question first. We do not support searching/indexing ACF repeater fields as they are too complex (theoretically they can have infinite nesting of fields, and the server load has the potential of being massive). We do support simple relational fields, like Post Type Object, but we fetch back the Title or ID back only.
Assuming that the search field is within a Search & Filter form, our plugin does not directly allow you to do text searches of individual Post Meta and Taxonomy data/terms. The Search & Filter Pro Text Search field uses the standard WordPress search, so looks only in the Post Title and Content. To help you control this better, on the form’s Advanced settings tab you will see 2 settings for Relevanssi.
The documentation for this is here:
https://www.designsandcode.com/documentation/search-filter-pro/3rd-party/relevanssi/
You would need to install and activate the free Relevanssi plugin as well.
Then set it up and build its index (make sure it is indexing the desired post types AND the taxonomies/custom fields that you want to search).
-
AuthorPosts