Answers.Body: <p>At the same time as you are iterating over your Hero posts, you could populate an array that you could then use in your most popular query.</p>
  <p>This is just sudo code but hopefully you get the idea:</p>
  <pre class="lang-twig prettyprint-override"><code>{# This would go before your hero loop #}
  {# Initiate a heroIds array starting with not #}
  {% set heroIds = ['not'] %}
  
  {% for entry in heroEntries %}
      {# Add  heroEntries id to your heroIds array #}
      {% set heroIds = heroIds | merge([entry.id]) %}
  
      {# the rest of your code... #}
  {% endfor %}
  
  {# Then you can use this array in your most popular query #}
  {% set entries = craft
      .entries()
      .section('news')
      .limit('4')
      .orderBy('popular')
      .id(heroIds)
      .all() %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-15T06:10:52.473Z
Answers.Text: Worked a treat! Thanks.
Answers.UserDisplayName: MarkD
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-14T11:03:16.900Z
Answers.LastActivityDate: 2020-07-14T16:47:37.270Z
Answers.LastEditDate: 2020-07-14T16:47:37.270Z
Answers.UserDisplayName: Oli
Body: <p>I have an Entries field so I can select a number of posts to feature in a &quot;Hero&quot; section on the home page, as well as a &quot;most popular&quot; section underneath it.</p>
  <p>However, the Hero posts keep showing up in this section, so I'd like to exclude them from the query.</p>
  <p>Is there a way I can get the array of entry id's from the Hero section and insert it into the popular query?</p>
  <p>Am using the Trendin Posts plugin (<a href="https://github.com/madebyraygun/trending-posts" rel="nofollow noreferrer">https://github.com/madebyraygun/trending-posts</a>) to get the popular posts.</p>
  <pre><code>{% set entries = craft.entries().section('news').limit('4').orderBy('popular').all() %}
  </code></pre>
  <p>and I would like...</p>
  <pre><code>{% set entries = craft.entries().section('news').limit('4').orderBy('popular').id('not', {array of IDs from Hero}).all() %}
  </code></pre>
  
Tags: <entry><array><queries>
Title: Help with an Entries field to an array I can use elsewhere
ThreadText: # Help with an Entries field to an array I can use elsewhere
  
  (Asked by: username_0 on 2020-07-14)
  
  I have an Entries field so I can select a number of posts to feature in a "Hero" section on the home page, as well as a "most popular" section underneath it.
  
  However, the Hero posts keep showing up in this section, so I'd like to exclude them from the query.
  
  Is there a way I can get the array of entry id's from the Hero section and insert it into the popular query?
  
  Am using the Trendin Posts plugin (<https://github.com/madebyraygun/trending-posts>) to get the popular posts.
  
  ```
  {% set entries = craft.entries().section('news').limit('4').orderBy('popular').all() %}
  
  ```
  
  and I would like...
  
  ```
  {% set entries = craft.entries().section('news').limit('4').orderBy('popular').id('not', {array of IDs from Hero}).all() %}
  
  ```
  
  **Tags:** entry, array, queries
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-07-14. Score: 3 | Accepted answer
  
  At the same time as you are iterating over your Hero posts, you could populate an array that you could then use in your most popular query.
  
  This is just sudo code but hopefully you get the idea:
  
  ```twig
  {# This would go before your hero loop #}
  {# Initiate a heroIds array starting with not #}
  {% set heroIds = ['not'] %}
  
  {% for entry in heroEntries %}
      {# Add  heroEntries id to your heroIds array #}
      {% set heroIds = heroIds | merge([entry.id]) %}
  
      {# the rest of your code... #}
  {% endfor %}
  
  {# Then you can use this array in your most popular query #}
  {% set entries = craft
      .entries()
      .section('news')
      .limit('4')
      .orderBy('popular')
      .id(heroIds)
      .all() %}
  
  ```
  
  > **Comments:**
  > **username_0**: Worked a treat! Thanks.  
  
  ---
  
  