Answers.Body: <p>You can grab all ids and exclude them from your query</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set excludeIds = craft.categories.group('services').relatedTo(entry).ids() %}
  {% for category in craft.categories.where(['!=', 'elements.id', excludeIds]).all() %}
  </code></pre>
  
  <p>If your relation field is in your entry you can do</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set categories = craft
      .categories
      .section('services')
      .where(['!=', 'elements.id', entry.category.ids()])
      .all()
  %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-04T09:56:22.897Z
Answers.Text: Thanks Robin. I'm still having a problem with this though, as it's now generating a database exception. This is what I have now:
  
      `<ul>
          {% set excludeIds = craft.categories.group('services').relatedTo(entry).ids() %}
          {% for category in craft.categories.where(['!=', 'elements.id', excludeIds]).all() %}
              <li>{{ category.title }}</li>
          {% endfor %}
      </ul>`
Answers.UserDisplayName: Eboon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-04T07:32:09.730Z
Answers.LastActivityDate: 2018-09-04T07:32:09.730Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I'm trying to output a list of categories that are <strong>not</strong> related to a particular entry (in order to show a list of services other than the service related to the current entry).</p>
  
  <p>I have this code which lists the category that <strong>is</strong> related to the current entry:</p>
  
  <pre><code>&lt;ul&gt;
    {% set categories = craft.categories.group('services').relatedTo(entry).all() %}
    {% nav category in categories %}
      &lt;li&gt;{{ category.title }}&lt;/li&gt;
    {% endnav %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>Is there a way of turning this on its head, so that the other, non-related categories are displayed? Something like a <code>notRelatedTo(entry)</code> parameter?</p>
  
Tags: <craft3><categories><relatedto>
Title: Display categories not related to an entry
ThreadText: # Display categories not related to an entry
  
  (Asked by: username_0 on 2018-09-03)
  
  I'm trying to output a list of categories that are **not** related to a particular entry (in order to show a list of services other than the service related to the current entry).
  
  I have this code which lists the category that **is** related to the current entry:
  
  ```
  <ul>
    {% set categories = craft.categories.group('services').relatedTo(entry).all() %}
    {% nav category in categories %}
      <li>{{ category.title }}</li>
    {% endnav %}
  </ul>
  
  ```
  
  Is there a way of turning this on its head, so that the other, non-related categories are displayed? Something like a `notRelatedTo(entry)` parameter?
  
  **Tags:** craft3, categories, relatedto
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-09-04. Score: 1
  
  You can grab all ids and exclude them from your query
  
  ```twig
  {% set excludeIds = craft.categories.group('services').relatedTo(entry).ids() %}
  {% for category in craft.categories.where(['!=', 'elements.id', excludeIds]).all() %}
  
  ```
  
  If your relation field is in your entry you can do
  
  ```twig
  {% set categories = craft
      .categories
      .section('services')
      .where(['!=', 'elements.id', entry.category.ids()])
      .all()
  %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks username_1. I'm still having a problem with this though, as it's now generating a database exception. This is what I have now:      `<ul>         {% set excludeIds = craft.categories.group('services').relatedTo(entry).ids() %}         {% for category in craft.categories.where(['!=', 'elements.id', excludeIds]).all() %}             <li>{{ category.title }}</li>         {% endfor %}     </ul>`  
  
  ---
  
  