Using custom fields in suggestions results

  • markus
    Participant
    3 years, 8 months ago #21522

    Hi,

    I have added a few custom fields for pages by using Advanced Custom Fields plugin. I’d like to use them when showing real-time search suggestions results. I can choose the fields to be indexed in the settings (2.2 Data) but how can I show e.g. an icon associated to a specific page in suggestions? I know I can use a twig template to define how suggestions results are displayed but the result data set doesn’t include those custom fields.
    Does the ACF extension have to be activated from WPSolr settings (1. Activate extensions)? If I activate it, I can’t choose which fields to search in (2.2. Data).

    BR

    wpsolr
    Keymaster
    3 years, 8 months ago #21523

    Suggestions are showing objects with an archive, like post types and taxonomies. Custom fields do not have an archive, therefore there would be no link to redirect to in the suggestions.

    For WooCommerce, attributes are taxonomies, hence they can be show in suggestions.

    wpsolr
    Keymaster
    3 years, 8 months ago #21524

    For you other questions on ACF, please create a new topic.

    markus
    Participant
    3 years, 8 months ago #21542

    Thank you for your reply!

    I kind of found a workaround how to display a value of ACF field in suggestions but I still have some questions. I’ll create a new topic because these questions are related to ACF.

    wpsolr
    Keymaster
    3 years, 8 months ago #21547

    Sorry, I misunderstood your question.

    You wanted to display some custom fields inside the results, not showing custom fields as results.

    For that, you could use the hook WPSOLR_Events::WPSOLR_FILTER_SOLR_RESULTS_APPEND_CUSTOM_HTML, and add a section ‘custom_html’ in your custom twig template, for example:

    {% if result.custom_html %}
     {{ result.custom_html }}
    {% endif %}
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.