1

I've got a site with multiple locales and I want to merge together content from across these locales, eg News.

The two sections share the same fields so should theoretically be able to be sorted by a shared criteria.

Looking at the post at How do I sort a collection of entries from multiple sections by date? I can merge these both into a single array but when I try to post the ids from these into a new query (to sort the results) only one set of results are returned.

Sample code:

{% set ids = craft.entries.section('news' ~ Section).relatedTo(active).ids() %}
{% set mergeIds = craft.entries.section('newsAlumni').status(null).locale('prior_alum').search('shareNewsAlumni:1').localeEnabled(false).ids() %}
{% set ids = ids|merge(mergeIds) %}

{% set news = craft.entries.id(ids).localeEnabled(false).status(null).order(['stickyNews desc','postDate desc']).ids() %}

If I dump the results of ids I get:

295484 | 3747 | 1787 | 1783 | 1781 | 1778 | 638 | 636 | 640 | 295486

295486 being the entry from mergeIds being returned. However, if I dump the results of news I get:

295484 | 3747 | 1787 | 1783 | 1781 | 1778 | 638 | 636 | 640

Leaving out the result from mergeIds. Any thoughts on why the entries from mergeIds are not being included in the resulting news object?

Ta

Cole

1 Answer 1

3

With that last {% set news = craft.entries.id(ids) %} criteria model you're querying in one locale only and there's no way to change that, Craft doesn't have a feature to set up a criteria model to query in multiple locales.

You'd have to merge the entry models themselves and use something like the Super Sort plugin to bring them in order.

{% set entriesA = craft.entries.section('news' ~ Section).relatedTo(active).ids() %}
{% set entriesB = craft.entries.section('newsAlumni').status(null).locale('prior_alum').search('shareNewsAlumni:1').localeEnabled(false).ids() %}
{% set entries = entriesA|merge(entriesB) %}

{% set entries = entries|supersort('sortAs', '{postDate}')|reverse %}
{% set entries = entries|supersort('sortAs', '{stickyNews}') %}
1
  • Thanks Carl - that was the approach taken: {% set pages = [] %} {% set pages = craft.entries.section('news' ~ Section).relatedTo(active).localeEnabled(false) %} {% set newsAlum = craft.entries.section('newsAlumni').relatedTo(active).status(null).locale('prior_alum').search('shareNewsAlumni:1').localeEnabled(false) %} {% set pages = pages|merge(newsAlum) %} {% set news = pages | supersort('rsortAs', "{ postDate|date('Ymd') }") %} Commented Apr 1, 2016 at 13:02

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.