Answers.Body: <p>If you want to do it in a single query, <a href="https://craftcms.stackexchange.com/a/10460/45">Marion's answer</a> is probably the best.</p>
  
  <p>Otherwise, you could do something like this:</p>
  
  <pre><code>{% set idsHavingCategory = craft.entries.section('news').relatedTo(category).limit(null).ids() %}
  
  {% set omitIds = 'and, not ' ~ idsHavingCategory|join(', not ') %}
  
  {% set entries = craft.entries.section('news').id(omitIds) %}
  </code></pre>
  
  <p>Inspired by this article, which shows how to (1) grab ids, and (2) query against them:</p>
  
  <blockquote>
    <p><a href="http://webstoemp.com/blog/manipulating-craft-elementcriteriamodel-with-twig/" rel="noreferrer">http://webstoemp.com/blog/manipulating-craft-elementcriteriamodel-with-twig/</a></p>
  </blockquote>
  
  <p>Also references related solutions found in these answers:</p>
  
  <ul>
  <li><a href="https://craftcms.stackexchange.com/a/4930/45">https://craftcms.stackexchange.com/a/4930/45</a></li>
  <li><a href="https://craftcms.stackexchange.com/a/4573/45">https://craftcms.stackexchange.com/a/4573/45</a></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-08T15:20:05.470Z
Answers.Text: I know, old question. But any idea how to combine this with a separate query? I'm looking to list entries that either do not have a category, or a specific category. It's proving to be quite a challenge.
Answers.UserDisplayName: InanisAtheos
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-08T18:25:29.633Z
Answers.Text: @Athoxx If you want to merge two queries, here is an [old article](https://www.webstoemp.com/blog/manipulating-craft-elementcriteriamodel-with-twig/) (it describes Craft 2) which does a great job of explaining the basic concept. Perform both queries and get **ids**, then use the IDs in a follow up query.
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-03T19:48:12.907Z
Answers.LastActivityDate: 2015-07-03T19:48:12.907Z
Answers.LastEditDate: 2017-04-13T12:51:00.160Z
Answers.UserDisplayName: Lindsey D
Answers.Body: <p>I got this to work with <a href="http://buildwithcraft.com/docs/searching" rel="noreferrer">search</a>:</p>
  
  <pre><code>{% set uncategorizedEntries
    = craft.entries.section('news').search('-category:*') %}
  </code></pre>
  
  <p>Here <code>category</code> is the category field. You are searching everything in <code>news</code> which does <em>not</em> have a <code>category</code> field that matches <code>*</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-03T14:52:31.483Z
Answers.Text: hmm yea i guess that would work but i cant imagine thats very performant.  Hoping theres a more direct route to get this to work but maybe not yet.
Answers.UserDisplayName: Keith Mancuso
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-02T19:43:33.303Z
Answers.LastActivityDate: 2015-07-02T19:43:33.303Z
Answers.UserDisplayName: Marion Newlevant
Answers.Body: <p>Another approach -- that might work for you -- is to filter on the output, rather than the query. For instance, using this query:</p>
  
  <pre><code>{% set entries = craft.entries.section('news') %}
  </code></pre>
  
  <p>Output using this loop:</p>
  
  <pre><code>{% for entry in entries if entry.category is empty %}
      ...
  {% endfor %}
  </code></pre>
  
  <p>YMMV</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-09T00:20:56.100Z
Answers.LastActivityDate: 2016-03-09T00:20:56.100Z
Answers.UserDisplayName: Brett Gullan
Answers.Body: <p>Not sure if this will help much, but I did something similar with:</p>
  
  <p><code>{% set allNews = craft.entries.section('news') %)</code></p>
  
  <p>Then:</p>
  
  <p><code>{% for entry in allNews.id("not #{category.id}")</code> ... <code>{% endfor %}</code></p>
  
  <p>Hope that helps in some way. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-02T17:56:58.807Z
Answers.Text: On second thought, I don't think this is going to be what you're looking for. I'll leave it though, in-case it helps in some other way.
Answers.UserDisplayName: Nicolaides
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-03T14:51:38.317Z
Answers.Text: yea thats not really what i need i need to fet all the entries not in a category
Answers.UserDisplayName: Keith Mancuso
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-02T17:11:27.803Z
Answers.LastActivityDate: 2015-07-02T17:20:11.073Z
Answers.LastEditDate: 2015-07-02T17:20:11.073Z
Answers.UserDisplayName: Nicolaides
Body: <p>is it possible to grab all the entries in a section that arent related to a category?</p>
  
  <p>So something like</p>
  
  <pre><code>craft.entries.section('news').relatedTo('not',category)
  </code></pre>
  
  <p>Doesnt seem to work but is there some other syntax?</p>
  
Tags: <relations>
Title: Get entries NOT related to categories
ThreadText: # Get entries NOT related to categories
  
  (Asked by: username_0 on 2015-07-02)
  
  is it possible to grab all the entries in a section that arent related to a category?
  
  So something like
  
  ```
  craft.entries.section('news').relatedTo('not',category)
  
  ```
  
  Doesnt seem to work but is there some other syntax?
  
  **Tags:** relations
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_1 on 2015-07-03. Score: 8
  
  If you want to do it in a single query, [username_3's answer](https://craftcms.stackexchange.com/a/10460/45) is probably the best.
  
  Otherwise, you could do something like this:
  
  ```
  {% set idsHavingCategory = craft.entries.section('news').relatedTo(category).limit(null).ids() %}
  
  {% set omitIds = 'and, not ' ~ idsHavingCategory|join(', not ') %}
  
  {% set entries = craft.entries.section('news').id(omitIds) %}
  
  ```
  
  Inspired by this article, which shows how to (1) grab ids, and (2) query against them:
  
  > <http://webstoemp.com/blog/manipulating-craft-elementcriteriamodel-with-twig/>
  
  Also references related solutions found in these answers:
  
  * <https://craftcms.stackexchange.com/a/4930/45>
  * <https://craftcms.stackexchange.com/a/4573/45>
  
  > **Comments:**
  > **username_2**: I know, old question. But any idea how to combine this with a separate query? I'm looking to list entries that either do not have a category, or a specific category. It's proving to be quite a challenge.  
  > **username_1**: @Athoxx If you want to merge two queries, here is an [old article](https://www.webstoemp.com/blog/manipulating-craft-elementcriteriamodel-with-twig/) (it describes Craft 2) which does a great job of explaining the basic concept. Perform both queries and get **ids**, then use the IDs in a follow up query.  
  
  ---
  
  ### Answer by username_3 on 2015-07-02. Score: 5
  
  I got this to work with [search](http://buildwithcraft.com/docs/searching):
  
  ```
  {% set uncategorizedEntries
    = craft.entries.section('news').search('-category:*') %}
  
  ```
  
  Here `category` is the category field. You are searching everything in `news` which does *not* have a `category` field that matches `*`.
  
  > **Comments:**
  > **username_0**: hmm yea i guess that would work but i cant imagine thats very performant.  Hoping theres a more direct route to get this to work but maybe not yet.  
  
  ---
  
  ### Answer by username_4 on 2016-03-09. Score: 3
  
  Another approach -- that might work for you -- is to filter on the output, rather than the query. For instance, using this query:
  
  ```
  {% set entries = craft.entries.section('news') %}
  
  ```
  
  Output using this loop:
  
  ```
  {% for entry in entries if entry.category is empty %}
      ...
  {% endfor %}
  
  ```
  
  YMMV
  
  
  ---
  
  ### Answer by username_5 on 2015-07-02. Score: 1
  
  Not sure if this will help much, but I did something similar with:
  
  `{% set allNews = craft.entries.section('news') %)`
  
  Then:
  
  `{% for entry in allNews.id("not #{category.id}")` ... `{% endfor %}`
  
  Hope that helps in some way.
  
  > **Comments:**
  > **username_5**: On second thought, I don't think this is going to be what you're looking for. I'll leave it though, in-case it helps in some other way.  
  > **username_0**: yea thats not really what i need i need to fet all the entries not in a category  
  
  ---
  
  