1

I really want something like this to work but the merge function turns Elements into Arrays. I've managed to work around it other times but what's the best practice to combine two entry sets and then paginate?

{% set cat1 = craft.categories.group("catAttributes").slug('diabetic').one %}

{% set firstEntries = craft.entries.section("cats").relatedTo([cat1]) %}

{% set secondEntries = craft.entries.section("cats").showInOtherOnCatsWithNeeds('1') %}

{% set allEntries = firstEntries | merge(secondEntries) %}

{% paginate allEntries.limit(12) as pageInfo, pet %}
2

I think you're correct in how you currently do it. You can't merge Element Queries, you can merge IDs (or any array of anything, really). The only thing you should remove, is the all when settings posts, because paginate expects an element query, not an array of elements.

|improve this answer|||||
  • You are correct! I didn't test the code before posting so I'll go ahead and edit that. – Matthew Rotter May 9 '19 at 15:08
  • I just wasn't sure if there was some sexy way to combine both queries into a single line instead – Matthew Rotter May 9 '19 at 15:15
  • I don’t think there’s a way to combine relatedTo with a custom field condition and achieve what you want to achieve. – Paul May 9 '19 at 15:20
1

Here's how I'd do it currently:

{% set cat1 = craft.categories.group("catAttributes").slug('diabetic').one %}

{% set firstEntries = craft.entries.section("cats").relatedTo([cat1]).ids() %}

{% set secondEntries = craft.entries.section("cats").showInOtherOnCatsWithNeeds('1').ids() %}

{% set allEntries = firstEntries | merge(secondEntries) %}

{% set posts = craft.entries.id( allEntries ) %}

{% paginate posts.limit(12) as pageInfo, pet %}
|improve this answer|||||

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.