<p>This is because of the way Element queries are in Craft 3.</p>

<p>In Craft 2, each time you called a setter method (<code>search()</code> here) it would clone your <code>ElementCriteriaModel</code>, use that value <strong>on the clone</strong> and return the cloned object leaving the original alone.</p>

<p>In Craft 3, when you call a setter method, it gets set on the current element query.</p>

<p>So if I understood correctly, you should use <code>clone</code> (<a href="https://docs.craftcms.com/v3/dev/functions.html#clone" rel="nofollow noreferrer">docs</a>):</p>

<pre><code>{% set entries = craft.entries().section('yourSection') %}
{{entries.all()|length}}

{% set hasTopic = clone(entries).search('dataTable_topic:*').all() %}
{{entries|length}} | {{ hasTopic|length }}
</code></pre>

CC BY-SA 4.0
2020-02-14T18:26:31.800Z
Thank you! That was it
Kenyon
CC BY-SA 4.0
2020-02-14T18:02:08.830Z
2020-02-14T18:02:08.830Z
Oli
<p>Kind of hard to explain but here's an example:</p>

<pre><code>{{entries.all()|length}} {# outputs 88 #}

{% set hasTopic = entries.search('dataTable_topic:*').all() %}
{{entries|length}} {# outputs 7 #}
</code></pre>

<p>How can I keep <code>entries</code> the same below the search variable.</p>

<search><field>
Setting a field search variable after main entries variable changes values
# Setting a field search variable after main entries variable changes values

(Asked by: username_0 on 2020-02-14)

Kind of hard to explain but here's an example:
{{entries.all()|length}} {# outputs 88 #}

{% set hasTopic = entries.search('dataTable_topic:*').all() %}
{{entries|length}} {# outputs 7 #}

How can I keep entries the same below the search variable.

**Tags:** search, field


---

## 1 answers

### Answer by username_1 on 2020-02-14. Score: 1 | Accepted answer

This is because of the way Element queries are in Craft 3.
In Craft 2, each time you called a setter method (search() here) it would clone your ElementCriteriaModel, use that value on the clone and return the cloned object leaving the original alone.
In Craft 3, when you call a setter method, it gets set on the current element query.
So if I understood correctly, you should use clone (docs):
{% set entries = craft.entries().section('yourSection') %}
{{entries.all()|length}}

{% set hasTopic = clone(entries).search('dataTable_topic:*').all() %}
{{entries|length}} | {{ hasTopic|length }}

> **Comments:**
> **username_0**: Thank you! That was it  

---

