Answers.Body: <p><strong>Update</strong>: This solution doesn't work, but no-one can explain why (maybe a Craft bug?). I'm leaving the code for reference though.</p>
  
  <p>--</p>
  
  <p>You could get them with a <code>craft.assets</code> element criteria model and a <code>relatedTo</code> param. Just pass a <code>'and, not 8, not 13, not 26'</code> type of string to <code>sourceElement</code>, with all element IDs listed that you want to exclude from an otherwise <code>limit: null</code> assets query.</p>
  
  <pre><code>{% set allEntryIds = craft.entries.limit(null).ids() %}
  {% set allCategoryIds = craft.categories.limit(null).ids() %}
  
  {% set omitIds = allEntryIds|merge([allCategoryIds]) %}
  {% set idsParam = 'and, not ' ~ omitIds|join(', not ') %}
  
  {% set unusedAssets = craft.assets({
      relatedTo: {
          sourceElement: idsParam,
      },
      limit: 0,
  }) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-10T13:30:42.747Z
Answers.Text: I get an "Array to string conversion" error on the line where you join the omitIds, is there a way around that?
Answers.UserDisplayName: Jai Sandhu
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-19T11:23:50.693Z
Answers.LastActivityDate: 2015-11-19T12:19:08.170Z
Answers.LastEditDate: 2015-11-19T12:19:08.170Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>With good help from @carlcs here and on Slack, we found a solution:</p>
  
  <pre><code>{% set allEntryIds = craft.entries.limit(null).ids() %}
  
  {% set usedAssets = craft.assets({
      relatedTo: allEntryIds,
      limit: null,
  }).ids() %}
  {% set unusedAssets = craft.assets({
      id: 'and, not ' ~ usedAssets|join(', not '),
      limit: null
  }) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-29T10:29:14.853Z
Answers.Text: Keep in mind, this is for all assets not used by *entries only*, they could be used by other elements like craft commerce products.
Answers.UserDisplayName: Luke Holder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-29T11:11:01.483Z
Answers.Text: Yes, and even other assets I discovered :)
Answers.UserDisplayName: megatrond
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-19T13:03:32.770Z
Answers.LastActivityDate: 2015-11-19T13:03:32.770Z
Answers.UserDisplayName: megatrond
Body: <p>How could I go about fetching all assets that are not currently beeing used anywhere?</p>
  
Tags: <assets><elementcriteriamodel>
Title: Fetch all unused assets?
ThreadText: # Fetch all unused assets?
  
  (Asked by: username_0 on 2015-11-19)
  
  How could I go about fetching all assets that are not currently beeing used anywhere?
  
  **Tags:** assets, elementcriteriamodel
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2015-11-19. Score: 7 | Accepted answer
  
  With good help from @username_0 here and on Slack, we found a solution:
  
  ```
  {% set allEntryIds = craft.entries.limit(null).ids() %}
  
  {% set usedAssets = craft.assets({
      relatedTo: allEntryIds,
      limit: null,
  }).ids() %}
  {% set unusedAssets = craft.assets({
      id: 'and, not ' ~ usedAssets|join(', not '),
      limit: null
  }) %}
  
  ```
  
  > **Comments:**
  > **username_3**: Keep in mind, this is for all assets not used by *entries only*, they could be used by other elements like craft commerce products.  
  > **username_2**: Yes, and even other assets I discovered :)  
  
  ---
  
  ### Answer by username_0 on 2015-11-19. Score: 1
  
  **Update**: This solution doesn't work, but no-one can explain why (maybe a Craft bug?). I'm leaving the code for reference though.
  
  --
  
  You could get them with a `craft.assets` element criteria model and a `relatedTo` param. Just pass a `'and, not 8, not 13, not 26'` type of string to `sourceElement`, with all element IDs listed that you want to exclude from an otherwise `limit: null` assets query.
  
  ```
  {% set allEntryIds = craft.entries.limit(null).ids() %}
  {% set allCategoryIds = craft.categories.limit(null).ids() %}
  
  {% set omitIds = allEntryIds|merge([allCategoryIds]) %}
  {% set idsParam = 'and, not ' ~ omitIds|join(', not ') %}
  
  {% set unusedAssets = craft.assets({
      relatedTo: {
          sourceElement: idsParam,
      },
      limit: 0,
  }) %}
  
  ```
  
  > **Comments:**
  > **username_1**: I get an "Array to string conversion" error on the line where you join the omitIds, is there a way around that?  
  
  ---
  
  