Craft CMS Asked by Less and More Collective on November 29, 2020
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!
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 %}
Correct answer by Pavel Pavlovich on November 29, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP