I have search high and low for a way to make the default WordPress search include custom fields.
It was a long and arduous quest, let me tell you.
I was able to use a bit of code that someone put up on github (custom-search-acf-wordpress) and have it successfully returned matches for my ACF repeater fields. However, it took well over a minute to load the search result page which is unacceptable. (I also had the exact same thing happen with the use of the Relevanssi plugin – matches to ACF repeater fields were picked up, but again it took forever to load.)
This data NEEDS to be searchable, so I’ve currently given up on using the repeater field for that particular data because of this. (I was able to include non-repeater custom fields in the default WP search at regular speed – if you want the code feel free to ask.)
Can anyone tell me if/how it would be possible to include the repeater fields in the search while keeping the load time at a decent speed?
Currently, we have not found a way to search repeater field data with fast speeds. This is due to the way in which WP saves data and the way in which ACF saves the repeater field data.
Perhaps you could think about caching the search results or using a transient to temp save the data?
Perhaps you could explain what your data setup is and what the search functionality needs to do.
My project is a blog where they will periodically be posting featured weddings. It is a custom with these types of blogs that they will have a list of acknowledgements at the bottom of the post that tells the reader where they got the cake, the flower arrangements and things like that.
I thought the repeater field would be perfect since the size and contents of the list could differ greatly from post to post.
Since this can still be easily input via a custom field with a WYSIWYG editor, it’s not worth the time/trouble to figure out how to make the repeater fields searchable for me at this time.
I -am- still using the repeater field for these same blog posts so that the blogger can create a photo gallery (though in hindsight my client would’ve been better off if I went with the Gallery plugin for this project instead).
Once I found out the way that repeater fields are stored in the database, mycustomfield_0_mysubfield, mycustomfield_1_mysubfield, and soforth, I thought if I could somehow return a list of those meta_keys so that I could put them in my array of custom fields it might work…
eg. $custom_fields = array(‘mycustomfield_0_mysubfield’, ‘mycustomfield_1_mysubfield’);
But it would differ depending on the post… so I’m not sure if that would work. Here is my code: pastebin
Perhaps you missed it, but there is a much nicer way to code this and is explained on the docs page here:
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Advanced Custom Fields @wp_acf is a great plugin for managing custom fields and other meta information. Check out the recording of @GUAlumni's talk at #WPCampus to learn how it can now help you build #Gutenberg blocks! #WordPress #HigherEd #EdTech #heweb https://t.co/MXuCTTsX3b— WPCampus (@wpcampusorg) November 16, 2019
© 2019 Advanced Custom Fields. Subscribe