<p>Try adding <code>find()</code> to your ElementCriteriaModel, I think without that function you're not actually saving your entries as an array in your variable <code>todaysOneOffEvents</code> yet.</p>

<p>Here's what I <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel#fetching-the-elements" rel="nofollow">found in the Docs</a>:</p>

<blockquote>
  <p>You don’t actually need to call <code>find()</code> yourself though: It will be called automatically as soon as the ElementCriteriaModel is treated like an array (that is, as soon as you check how many elements there are using the <code>|length</code> filter, or start looping through the elements with a <code>{% for %}</code> loop).</p>
</blockquote>

<p>We learn that merging doesn't "treat it like an array", good to know.</p>

<p>Edit: You can't use the <code>length</code> filter to "convert" the content of the variable to an actual array. Removed that part from the answer.</p>

CC BY-SA 3.0
2014-10-22T14:00:38.660Z
That's the bunny. Cheers.
Clive Portman
CC BY-SA 3.0
2014-10-21T14:38:54.120Z
2014-10-21T15:02:02.410Z
2014-10-21T15:02:02.410Z
carlcs
<p>Can anyone help me work out why the following returns the error "The merge filter only works with arrays or hashes."?</p>

<pre><code>{# CREATE ARRAY TO HOLD ALL OF TODAY'S EVENTS #}
{% set todaysEvents = [] %}

{# GET TODAY'S ONE-OFF EVENTS #}
{# RETURNS ENTRIES NICELY IF LOOPED THROUGH #}
{% set todaysOneOffEvents = craft.entries.section('events').eventDate('= '~today | date("Y-m-d")) %}

{# ADD TODAY'S ONE-OFF EVENTS TO TODAY'S EVENTS %}
{# THIS RETURNS MERGE ARRAY ERROR #}
{% set todaysEvents = todaysEvents|merge(todaysOneOffEvents) %}
</code></pre>

CC BY-SA 3.0
2014-10-21T15:11:07.673Z
Thanks to this I finally learned the difference between an ElementCriteriaModel an an array of entries. The magic happens within the `find()` function :) Thanks for the question, Clive!
carlcs
<array><merge>
Shouldn't this merge be working?
# Shouldn't this merge be working?

(Asked by: username_0 on 2014-10-21)

Can anyone help me work out why the following returns the error "The merge filter only works with arrays or hashes."?
{# CREATE ARRAY TO HOLD ALL OF TODAY'S EVENTS #}
{% set todaysEvents = [] %}

{# GET TODAY'S ONE-OFF EVENTS #}
{# RETURNS ENTRIES NICELY IF LOOPED THROUGH #}
{% set todaysOneOffEvents = craft.entries.section('events').eventDate('= '~today | date("Y-m-d")) %}

{# ADD TODAY'S ONE-OFF EVENTS TO TODAY'S EVENTS %}
{# THIS RETURNS MERGE ARRAY ERROR #}
{% set todaysEvents = todaysEvents|merge(todaysOneOffEvents) %}

**Tags:** array, merge
> **Comments:**
> **username_1**: Thanks to this I finally learned the difference between an ElementCriteriaModel an an array of entries. The magic happens within the `find()` function :) Thanks for the question, Clive!  

---

## 1 answers

### Answer by username_1 on 2014-10-21. Score: 6 | Accepted answer

Try adding `find()` to your ElementCriteriaModel, I think without that function you're not actually saving your entries as an array in your variable `todaysOneOffEvents` yet.

Here's what I [found in the Docs](http://buildwithcraft.com/docs/templating/elementcriteriamodel#fetching-the-elements):

> You don’t actually need to call `find()` yourself though: It will be called automatically as soon as the ElementCriteriaModel is treated like an array (that is, as soon as you check how many elements there are using the `|length` filter, or start looping through the elements with a `{% for %}` loop).

We learn that merging doesn't "treat it like an array", good to know.

Edit: You can't use the `length` filter to "convert" the content of the variable to an actual array. Removed that part from the answer.

> **Comments:**
> **username_0**: That's the bunny. Cheers.  

---

