1

My Code:

{% set Entries              =   craft.entries.section('not loanConsultants').search(searchQuery).orderBy('dateCreated desc').all() %}

{% set loanConsultants      =   craft.entries.section('loanConsultants').type('loanConsultants').search('title:'~searchQuery).orderBy('dateCreated desc').all() %}

{% set Branch               =   craft.entries.section('loanConsultants').type('branches').search('title:'~searchQuery).orderBy('dateCreated desc').all() %}

{% set loanConsultantsMerge = loanConsultants|merge(Branch) %}

{% set mergeResults         = loanConsultantsMerge|merge(Entries) %}

Pagination code:

{% paginate mergeResults as pageInfo, pageEntries %}
{% for entry in pageEntries %}
    <h5>{{ entry.title }}</h5>
{% endfor %}

{% if pageInfo.prevUrl %}<a href="{{ pageInfo.prevUrl }}" class="btn btn-success" style="color: blue;">Previous Page</a>{% endif %}

{% if pageInfo.nextUrl %}<a href="{{ pageInfo.nextUrl }}" class="btn btn-success" style="color: blue;">Next Page</a>{% endif %}

1 Answer 1

2

The paginate tag requires an element query to work and by calling .all() on your queries, you've turned them into an array of elements.

Something like this should work:

{# Grab all of the IDs #}
{% set entries = craft.entries.section('not loanConsultants').search(searchQuery).ids() %}

{% set loanConsultants = craft.entries.section('loanConsultants').type('loanConsultants').search('title:'~searchQuery).ids() %}

{% set branch =   craft.entries.section('loanConsultants').type('branches').search('title:'~searchQuery).ids() %}

{# Merge the IDs together #}
{% set loanConsultantsMerge = loanConsultants|merge(branch) %}
{% set mergeResults = loanConsultantsMerge|merge(entries) %}

{# Build new query #}
{% set results = craft.entries.id($mergeResults) %}

{% paginate results as pageInfo, pageEntries %}
{% for entry in pageEntries %}
    <h5>{{ entry.title }}</h5>
{% endfor %}

{% if pageInfo.prevUrl %}<a href="{{ pageInfo.prevUrl }}" class="btn btn-success" style="color: blue;">Previous Page</a>{% endif %}

{% if pageInfo.nextUrl %}<a href="{{ pageInfo.nextUrl }}" class="btn btn-success" style="color: blue;">Next Page</a>{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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