Home › Forums › Add-ons › Options Page › Results not showing when searching on a relationship field
I’m working with an options page to set up site wide configurations. I have a relationship field that lets me select some posts to be displayed on a site rail. The issue is that it turns out to be tremendously hard to find the content I’m looking for: even when I type in the exact post name the content won’t populate and I have to scroll way too much to find it on the results box.
Is there anything I can do to improve the search here?
even when I type in the exact post name the content won’t populate
Does that mean that you see nothing at all or that you see a lot of results?
I see a lot of results, but not the post I’m looking for (the one with the exact name I’m tying in)
The ACF relationship field uses the built in search mechanism. If any word you type is in the title or content of the post then it will appear in the list. If the exact phrase appears then it should be closer to the top, but it needs to be exact.
ACF only loads a few posts at a time, not sure of the number. If it stops before it has shown all the possibilities then there might be an error during the AJAX request. You might be able to figure out the error by turning on error logging.
Solved by implementing exact title search as explained here: https://www.isitwp.com/limit-search-to-post-titles-only/
You may want to consider only adding that filter for when the results of that field. To do that use https://www.advancedcustomfields.com/resources/acf-fields-relationship-query/ and put add_filter( 'posts_search', '__search_by_title_only', 500, 2 );
in that filter. Then it will only be used on that search rather than all searches on the site.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.