2

I have a multisite setup and and a search bar at the top of each site. Currently it just searches within that site:

{% set theSite = craft.app.request.getSegment(1) %}
{% paginate craft.entries.search(search).site(theSite).orderBy('score').limit(9) as pageInfo, pageEntries %}

The first segment defines the site. I need to expand the searches to include all entries in all sites. Is this possible? I tried variations of getAllSites and just .site but of course those didn't work.

If its not possible to search all sites at once I may look at running each search and adding all of the results together.

1

The Entries Query only allows you to search one site at a time. Here is the documentation for the Site Object or Site Id query params.

You can get each site by:

{% set sites = craft.app.sites.allSites %}
{% for site in sites %}
    …        
{% endfor %}
2

Currently, you unfortunately can't query all sites within your entires, you will have to separate your results out with a for-loop by site, as @aran did above.

Craft 3.2 will thankfully fix this by allowing you to pass sites to an array or query sites('*') to return entries from all your sites:

https://github.com/craftcms/cms/commit/d01702278bd84b84392e11da72aa4d0b6f4f0943

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.