1

I would like to use a query term for multiple fields according to their fields' handle in Craft cms 3.5.x, but unfortunately only for field title that works correctly, while for the other fields i get no results at all. Additionally i have also tried another method here without success.

            <h1>Search Results</h1>
           
            {% set queryParams = {} %}

            {% if craft.app.request.getParam('q') %}
                {% set searchQuery = craft.app.request.getParam('q') %}
                {% set queryParams = queryParams|merge({
                    search:{
                          query: 'appealer:' ~ searchQuery ~ ' OR  assigner:' ~ searchQuery ~ ' OR  title:' ~ searchQuery,
                        }
                       }) %}
                {% set queryEntries = craft.entries(queryParams).section('appeals') %}      

            {% endif %}

                {% if queryEntries|length %}
                  <p>{{ queryEntries|length }} results:</p>

                  <ol>
                    {% for entry in queryEntries %}
                      <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
                    {% endfor %}
                  </ol>
                {% else %}
                  <p>Your search for “{{ searchQuery }}” didn’t return any results.</p>
                {% endif %}

Any idea that could help me?

Regards

1

Have you checked that the custom fields are searchable by having the "Use this field’s values as search keywords" option checked? The value will be added to the index only after this is checked and the entry is saved. You can also rebuild the search index with a console command.

php craft resave/entries --update-search-index

I'd also recommend sticking to one syntax for the query, rather than mixing them, for ease of use.

{% set entryQuery = craft.entries().section('appeals') %}

{% set searchQuery = craft.app.request.getParam('q') %}
{% if searchQuery %}
    {% do entryQuery.search('appealer:' ~ searchQuery ~ ' OR  assigner:' ~ searchQuery ~ ' OR  title:' ~ searchQuery) %}
{% endif %}

{% set entries = entryQuery.all() %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.