0

I am trying to get all the entries that don't related to the current user via a user field.
I have used the following code to fetch all the entries that do related to the current user

{% set entries = craft.entries.section('movementCoursesEntries').level(1).relatedTo({
   targetElement: currentUser,
   field: 'permittedUsers'
}).find() %} 

When I try to exclude these entries from the rest of the entries in the structure, I get nothing

{% set unrelated = craft.entries.section('movementCoursesEntries').level(1)|without(entries) %}

{% for entry in unrelated %}
    {{ entry.title }}
{% endfor %}

Any idea how to filter those entries properly? Thank you!

0

Try this:

{% set entries = craft.entries.section('movementCoursesEntries').level(1).relatedTo({
   targetElement: currentUser,
   field: 'permittedUsers'
}).ids() | join(', not ') %}

{% set unrelated = craft.entries.section('movementCoursesEntries').level(1).id('and, not '~entries).all() %}

{% for entry in unrelated %}
    {{ entry.title }}
{% endfor %}
| 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.