<p>I'm trying to exclude the current entry for a set of related entries. I am targeting an entry field to grab the set of related entries. Here is the code I have:</p>
<pre><code>   {% if block.relatedPageEntries | length %}
      {% for entry in block.relatedPageEntries.all() %}
      {% set related = craft.entries({
        section:        'general',
        orderBy:         'title',
        relatedTo:       entry,
      }).id('not ' ~ entry.id) %}

      {% if related %}
      {% for entry in related %} ... {% endfor %}
      {% endif %}
     
      {% endfor %}
    {% endif %}

</code></pre>
<p>I am trying to use .id('not ' ~ entry.id) to exclude the current entry but that isn't working. I believe that it's because it's in the current for loop.</p>

<forloop>
Excluding current entry on related entries
# Excluding current entry on related entries

(Asked by: username_0 on 2023-03-29)

I'm trying to exclude the current entry for a set of related entries. I am targeting an entry field to grab the set of related entries. Here is the code I have:
   {% if block.relatedPageEntries | length %}
      {% for entry in block.relatedPageEntries.all() %}
      {% set related = craft.entries({
        section:        'general',
        orderBy:         'title',
        relatedTo:       entry,
      }).id('not ' ~ entry.id) %}

      {% if related %}
      {% for entry in related %} ... {% endfor %}
      {% endif %}
     
      {% endfor %}
    {% endif %}


I am trying to use .id('not ' ~ entry.id) to exclude the current entry but that isn't working. I believe that it's because it's in the current for loop.

**Tags:** forloop

---

## 0 answers

