Displaying posts' ACF fields in results

Tagged:
  • markus
    Participant
    2 years, 3 months ago #21546

    Hi,

    I wonder how I set what posts’ ACF fields are returned by the query.

    I managed to define those fields in add_fields function in class-wpsolr-abstractsearchclient.php, and then they are used by get_results_results function in the same file. Is that the way – should I really edit those core functions? I wonder if I miss something important.

    wpsolr
    Keymaster
    2 years, 3 months ago #21550

    WPSOLR returns posts to your theme’s loop: use ACF get_field() to retrieve your ACF values.

    markus
    Participant
    2 years, 3 months ago #21610

    Thank you for your reply.

    I assume this stands for showing results in a separate search page. How about displaying real-time search suggestions results? Does the same method apply when displaying result posts’ values (ACF fields) in suggestions? I tried to use that function in the WPSolr twig template (__theme_dir__/wpsolr-templates/twig/suggestions) but it didn’t seem to work.
    Alternatively, if it doesn’t work other way and I have to modify those plugin’s core files, can I somehow override them by my child theme?

    wpsolr
    Keymaster
    2 years, 3 months ago #21617

    When you’re configuring your suggestions in WPSOLR, there is a “Download and install this example child theme” link. The download zip file contains a full example of a child theme functions.php customizing both the suggestion template twig file and the data used by the twig template.

    Use ACF get_field() to add your ACF fields to the data, and modify the twig template to display the fields.

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

You must be logged in to reply to this topic.