Support

Account

Home Forums ACF PRO What is the best solution for a page searches with ACF Contents?

Solving

What is the best solution for a page searches with ACF Contents?

  • I use ACP Pro mostly with flexible content fields, repeaters, releationships (sometimes nested Repeaters in Flexible Contents). This all on pages and custom post types.

    I need an option to choose which fields in witch post types or pages should be in the search. And then a way how to display all the ACF contents in the search results.

    All I found is not a final way and looks more linke a workaround.

    I can work with a plugin or with the wp search, when the perfomance and flexibility is good.

  • Search everything is a quick solution https://wordpress.org/plugins/search-everything/, but it will have some performance issues if you have a large number of custom fields. I’ve actually seen this plugin cause sites to time out so you need to be careful where you use it.

    Your best choice is to create a pre_get_posts filter. There is a simple example of altering search results in the docs https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

    As far as displaying the values in the custom fields on search results, just like everything else in ACF, you’ll need to modify the template that shows the search results, usually search.php in your theme folder.

  • Thanks John,

    I think the pre_get_posts is the solution for me,
    but I have actually not that experience in writing mm own search.php templates.

    Have you or anyone else some more well explained ACF specific examples?

  • The documentation here on this give basic examples of the code needed to display every type of field. https://www.advancedcustomfields.com/resources/ other than the acf stuff the WP template is basically the same as any search results template in any theme.

  • Hi @bluesky,

    If you or someone is looking for a solution to searches content from ACF fields I recommend the plugin:
    https://wordpress.org/plugins/acf-better-search/

    This plugin adds to default WordPress search engine the ability to search by content from selected fields of Advanced Custom Fields plugin.

    Everything works automatically, no need to add any additional code.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.