Display categories not related to an entry 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:

&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;


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?
You can grab all ids and exclude them from your query

{% 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

{% set categories = craft
    .categories
    .section('services')
    .where(['!=', 'elements.id', entry.category.ids()])
    .all()
%}