Answers.Body: <p>Based on the bug report found here (<a href="https://github.com/craftcms/cms/issues/2160" rel="nofollow noreferrer">https://github.com/craftcms/cms/issues/2160</a>), I am now creating a variable that contains all of the items prior to filtering it.</p>
  
  <pre><code>{% set entries = craft.entries.type('publications').orderBy("postDate desc") %}
  {% set allEntries = entries.all() %}
  </code></pre>
  
  <p>I can then use entries to filter through the available categories and then use allEntries to loop through all of them.</p>
  
  <p>I understand I could also have used clone() to get a copy to work from in my category loop. </p>
  
  <pre><code>{% set catEntries = clone(entries).relatedTo(cat) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-09T20:37:16.403Z
Answers.LastActivityDate: 2018-05-09T21:01:51.270Z
Answers.LastEditDate: 2018-05-09T21:01:51.270Z
Answers.UserDisplayName: Eric Chantigny
Body: <p>This is from a template that worked in Craft 2, but doesn't in Craft 3.</p>
  
  <pre><code>{% set entries = craft.entries.type('publications').orderBy("postDate desc") %}
  </code></pre>
  
  <p>entries.count() outputs 80</p>
  
  <pre><code>{% for cat in allCats %}
      {% set catEntries = entries.relatedTo(cat) %}
      {% if catEntries | length or cat.slug=="all" or cat.slug=="toutes" %}
          &lt;li&gt;&lt;a href="{{ cat.url }}" {% if category is defined and cat.slug == category.slug %}class="current"{% endif %}&gt;{{ cat.title }}&lt;/a&gt;&lt;/li&gt;
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>This iterates through all categories with correct entries associated</p>
  
  <p>After that, entries.count() outputs 0</p>
  
  <p>Looks like entries is getting set to the last value instead of just passing the resulting object to the variable.  This is not how it worked before.  Is there a way to reset this ?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-09T19:12:31.867Z
Comments.Text: Probably a dupe of https://craftcms.stackexchange.com/questions/25613/missing-matrix-row-types-on-output-after-upgrade-to-craft-3-subsetting-and-clon ?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-09T20:18:41.767Z
Comments.Text: Hi @BradBell, I agree that it most be a dupe question, but the answer is not available where it ends up linking.
  https://docs.craftcms.com/v3/changes-in-craft-3.html#cloning-element-queries
  
  Would you care to give a proper answer and/or link to the actual explanation and how to get it done?
  
  Thanks
Comments.UserDisplayName: Eric Chantigny
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-09T20:34:52.090Z
Comments.Text: https://docs.craftcms.com/v3/templating/functions.html#clone-object please take a look at the comments https://github.com/craftcms/cms/issues/2160
Comments.UserDisplayName: Robin Schambach
Tags: <templating><entries><craft3>
Title: Entries object getting reset after a relatedTo query
ThreadText: # Entries object getting reset after a relatedTo query
  
  (Asked by: username_0 on 2018-05-09)
  
  This is from a template that worked in Craft 2, but doesn't in Craft 3.
  
  ```
  {% set entries = craft.entries.type('publications').orderBy("postDate desc") %}
  
  ```
  
  entries.count() outputs 80
  
  ```
  {% for cat in allCats %}
      {% set catEntries = entries.relatedTo(cat) %}
      {% if catEntries | length or cat.slug=="all" or cat.slug=="toutes" %}
          <li><a href="{{ cat.url }}" {% if category is defined and cat.slug == category.slug %}class="current"{% endif %}>{{ cat.title }}</a></li>
      {% endif %}
  {% endfor %}
  
  ```
  
  This iterates through all categories with correct entries associated
  
  After that, entries.count() outputs 0
  
  Looks like entries is getting set to the last value instead of just passing the resulting object to the variable. This is not how it worked before. Is there a way to reset this ?
  
  **Tags:** templating, entries, craft3
  
  > **Comments:**
  > **username_1**: Probably a dupe of https://craftcms.stackexchange.com/questions/25613/missing-matrix-row-types-on-output-after-upgrade-to-craft-3-subsetting-and-clon ?  
  > **username_0**: Hi @username_1, I agree that it most be a dupe question, but the answer is not available where it ends up linking. https://docs.craftcms.com/v3/changes-in-craft-3.html#cloning-element-queries  Would you care to give a proper answer and/or link to the actual explanation and how to get it done?  Thanks  
  > **username_2**: https://docs.craftcms.com/v3/templating/functions.html#clone-object please take a look at the comments https://github.com/craftcms/cms/issues/2160  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-05-09. Score: 1
  
  Based on the bug report found here (<https://github.com/craftcms/cms/issues/2160>), I am now creating a variable that contains all of the items prior to filtering it.
  
  ```
  {% set entries = craft.entries.type('publications').orderBy("postDate desc") %}
  {% set allEntries = entries.all() %}
  
  ```
  
  I can then use entries to filter through the available categories and then use allEntries to loop through all of them.
  
  I understand I could also have used clone() to get a copy to work from in my category loop.
  
  ```
  {% set catEntries = clone(entries).relatedTo(cat) %}
  
  ```
  
  
  ---
  
  