Answers.Body: <p>Solved by putting the event object into an array using square brackets.</p>
  
  <pre><code>{% set todaysEvents = todaysEvents|merge([event]) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-22T16:30:45.043Z
Answers.LastActivityDate: 2014-10-22T16:30:45.043Z
Answers.UserDisplayName: Clive Portman
Answers.Body: <p>The merge filter only works with 2 arrays (or 2 hashes), not with an array and an object. I think that the <code>event</code> you are trying to add is not an array, it is a single event (Entry Model). You might try adding the event using <code>[ event ]</code>.</p>
  
  <pre><code>{% set todaysEvents = todaysEvents|merge([event]) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-22T16:29:23.893Z
Answers.Text: Sorted. Use square brackets to create the array instead.
Answers.UserDisplayName: Clive Portman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-22T16:31:28.177Z
Answers.Text: I updated the answer.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-22T16:34:33.823Z
Answers.Text: Thanks Douglas. We got there about the same time. I've removed my comment about curly brackets as they're no longer in the answer.
Answers.UserDisplayName: Clive Portman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-22T16:37:08.863Z
Answers.Text: Glad you got it sorted! Those things can be incredibly frustrating. Been there ;)
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-22T16:08:11.620Z
Answers.LastActivityDate: 2014-10-22T16:30:11.760Z
Answers.LastEditDate: 2014-10-22T16:30:11.760Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>I'm trying to loop through some entries and if they fulfil a certain condition push them into another array of entries.</p>
  
  <pre><code>{% set todaysEvents = []
  {# GET TODAY'S ONE-OFF EVENTS #}
  {% set todaysOneOffEvents = craft.entries.section('events').eventDate('= '~today | date("Y-m-d")).find() %}
  
  {# ADD TODAY'S ONE-OFF EVENTS TO TODAY'S EVENTS #}
  {% set todaysEvents = todaysEvents|merge(todaysOneOffEvents) %}
  {# WORKING BEAUTIFULLY #}       
  
  {# FOR MULTI-DAY EVENTS THE DATES ARE IN A MATRIX FIELD, SO WE CAN'T FILTER USING CRAFT.ENTRIES #}
  {# INSTEAD, WE HAVE TO FILTER EVERY ENTRY IN EVENTS WHICH USE THE MULTI-DAY ENTRY TYPE #}
  {% for event in craft.entries.section('events').type('eventWithMultipleDays').find() %}
      {# NOW FIND ONLY ENTRIES WITH A MATRIX BLOCK CONTAINING TODAY'S DATE #}
      {% for date in event.dates if date.multiDate == today | date("Y-m-d") %}
          {# CORRECTLY IDENTIFIES ENTRY AS HAVING TODAY'S DATE IN A MATRIX BLOCK #}
          {# SO NOW WE ADD IT TO TODAYSEVENTS ARRAY #}
          {% set todaysEvents = todaysEvents|merge(event) %}
          {# ERROR: THE MERGE FILTER ONLY WORKS WITH ARRAYS OR HASHES #}      
      {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>What go on? See the error in the last comment. How do I pass only these filtered entries into todaysEvents array?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-10-22T15:51:46.807Z
Comments.Text: I'm trying to do a similar thing right now, looking forward to answers to this!
Comments.UserDisplayName: hamishtaplin
Tags: <array><merge>
Title: Adding entries to an array, one at a time
ThreadText: # Adding entries to an array, one at a time
  
  (Asked by: username_0 on 2014-10-22)
  
  I'm trying to loop through some entries and if they fulfil a certain condition push them into another array of entries.
  
  ```
  {% set todaysEvents = []
  {# GET TODAY'S ONE-OFF EVENTS #}
  {% set todaysOneOffEvents = craft.entries.section('events').eventDate('= '~today | date("Y-m-d")).find() %}
  
  {# ADD TODAY'S ONE-OFF EVENTS TO TODAY'S EVENTS #}
  {% set todaysEvents = todaysEvents|merge(todaysOneOffEvents) %}
  {# WORKING BEAUTIFULLY #}       
  
  {# FOR MULTI-DAY EVENTS THE DATES ARE IN A MATRIX FIELD, SO WE CAN'T FILTER USING CRAFT.ENTRIES #}
  {# INSTEAD, WE HAVE TO FILTER EVERY ENTRY IN EVENTS WHICH USE THE MULTI-DAY ENTRY TYPE #}
  {% for event in craft.entries.section('events').type('eventWithMultipleDays').find() %}
      {# NOW FIND ONLY ENTRIES WITH A MATRIX BLOCK CONTAINING TODAY'S DATE #}
      {% for date in event.dates if date.multiDate == today | date("Y-m-d") %}
          {# CORRECTLY IDENTIFIES ENTRY AS HAVING TODAY'S DATE IN A MATRIX BLOCK #}
          {# SO NOW WE ADD IT TO TODAYSEVENTS ARRAY #}
          {% set todaysEvents = todaysEvents|merge(event) %}
          {# ERROR: THE MERGE FILTER ONLY WORKS WITH ARRAYS OR HASHES #}      
      {% endfor %}
  {% endfor %}
  
  ```
  
  What go on? See the error in the last comment. How do I pass only these filtered entries into todaysEvents array?
  
  **Tags:** array, merge
  
  > **Comments:**
  > **username_1**: I'm trying to do a similar thing right now, looking forward to answers to this!  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2014-10-22. Score: 7 | Accepted answer
  
  The merge filter only works with 2 arrays (or 2 hashes), not with an array and an object. I think that the `event` you are trying to add is not an array, it is a single event (Entry Model). You might try adding the event using `[ event ]`.
  
  ```
  {% set todaysEvents = todaysEvents|merge([event]) %}
  
  ```
  
  > **Comments:**
  > **username_0**: Sorted. Use square brackets to create the array instead.  
  > **username_2**: I updated the answer.  
  > **username_0**: Thanks username_2. We got there about the same time. I've removed my comment about curly brackets as they're no longer in the answer.  
  > **username_2**: Glad you got it sorted! Those things can be incredibly frustrating. Been there ;)  
  
  ---
  
  ### Answer by username_0 on 2014-10-22. Score: 1
  
  Solved by putting the event object into an array using square brackets.
  
  ```
  {% set todaysEvents = todaysEvents|merge([event]) %}
  
  ```
  
  
  ---
  
  