4

I need to search both entries and assets and paginate the combined result.

I have tried:

{% set entries = craft.entries.search(query|trim).order('score').status('pending, live').find() %}
{% set assets = craft.assets.source('documentLibrary').search(query).find() %}
{% set searchResults = entries | merge(assets) %}

But then I can't get paginate to work:

{% paginate searchResults as results %}

... brings up the following error:

Argument 1 passed to Craft\TemplateHelper::paginateCriteria() must be an instance of Craft\ElementCriteriaModel, array given

If I don't use a .find(), I can't merge the two objects.

Any ideas how this can be achieved?

Lindsey D
  • 23,974
  • 5
  • 53
  • 110
Edin
  • 43
  • 2

1 Answers1

1

You're getting that error because as soon as you call find(), you're converting the ElementCriteriaModel into an array of actual fetched elements and the {% paginate %} tag requires an ElementCriteriaModel object to be passed in.

In order to pull off what you're looking for, you'd need to ability to search across multiple element types in one query, which is currently not something Craft supports.

Consider voting for this feature request, which would enable what you're trying to do.

Brad Bell
  • 67,440
  • 6
  • 73
  • 143
  • Thanks of letting me know.

    The only way I've managed to do this is by creating a specific channel and assigning an asset to an entry. It adds an extra step in the process but it's a feature we need for the website.

    – Edin Oct 21 '15 at 00:58