I got a list of entries news (channel type).
They are created by users (or author).
These users have a category region assigned to them.

My point is to list the news entries that have the same author's category than the currentUser's category...

I am trying with relatedTo but I am stuck here:

{% if currentUser %}
    {% set userRegion = currentUser.region.first() %}
{% endif %}

{% set regionNews = craft.entries.section('news').relatedTo('and',
    { sourceElement: currentUser, field: 'unepRegion' },
    { targetElement: author, field: 'unepRegion' }
) %}

Really don't know where I am going with this.


You probably have to query twice, first get all the users and then get all news entries published by any of these users using the authorId parameter on your criteria model.

{% set userRegion = currentUser.region.first() %}
{% set regionUsersIds = craft.users.relatedTo(userRegion).limit(null).ids() %}

{% set regionNews = craft.entries.section('news').authorId(regionUsersIds) %}
  • Genius! :D This idea arise in my head too when I woke this morning! :) Testing now... Tell you...
    – migswd
    Aug 30 '15 at 3:06
  • Worked like a charm :D Thx!
    – migswd
    Aug 30 '15 at 4:13

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.