<p>I am not sure if i get what you mean, do you want to have the categories as content blocks, which show the entries ordered by last updated, but the category blocks should be ordered as well e.g. if entry x in categort y is the newest the category block y should be on top of the list?</p>

<p>Otherwise that should work, displaying the latest 10 updated entries on top for 8 categories all in descending order relative the the update date</p>

<pre><code>   {% set categories = craft.categories({
         level: 1,
         limit: 8,
         orderBy: 'dateUpdated desc',
     }) 
  %}

  {% set offers = craft.entries({
     relatedTo: categories,
     with: ['offerLogo'],
     limit: 10,
     orderBy: 'dateUpdated desc',
     }) 
   %}

   {% for offer in offers %}
      {% include '_card' %}
   {% endfor %}
</code></pre>

CC BY-SA 4.0
2019-06-27T12:57:13.617Z
2019-06-27T13:26:56.130Z
2019-06-27T13:26:56.130Z
HendrikEng
<p>I have the following Category loop code which I'm trying to sort by the date the entries within have been updated. </p>

<blockquote>
  <p>e.g if an entry was just updated within a category, this category
  would be at the top of the page/loop.</p>
</blockquote>

<p>Here's my code</p>

<pre><code>  &lt;!-- START CATEGORY LOOP --&gt;
  {% set categories = craft.categories()
      .level('1')
      .limit('8')
      .all() %}

  {% for category in categories %}

       {% set offers = craft.entries({
            relatedTo: category,
            with: ['offerLogo'],
            limit: 10,
       }).all() %}

       {% for offer in offers %}
          {% include '_card' %}
       {% endfor %}

  {% endfor %}
</code></pre>

<p>I just can't get them to be ordered. Any help would be great!</p>

CC BY-SA 4.0
2019-06-27T12:49:10.363Z
doesn't orderBy: 'dateUpdated desc', work in your offers query? ahh you want to have the categories ordered as well
HendrikEng
<templating>
Sort Categories by Entry Updated
# Sort Categories by Entry Updated

(Asked by: username_0 on 2019-06-27)

I have the following Category loop code which I'm trying to sort by the date the entries within have been updated. 

e.g if an entry was just updated within a category, this category
  would be at the top of the page/loop.

Here's my code
  
  {% set categories = craft.categories()
      .level('1')
      .limit('8')
      .all() %}

  {% for category in categories %}

       {% set offers = craft.entries({
            relatedTo: category,
            with: ['offerLogo'],
            limit: 10,
       }).all() %}

       {% for offer in offers %}
          {% include '_card' %}
       {% endfor %}

  {% endfor %}

I just can't get them to be ordered. Any help would be great!

**Tags:** templating
> **Comments:**
> **username_1**: doesn't orderBy: 'dateUpdated desc', work in your offers query? ahh you want to have the categories ordered as well  

---

## 1 answers

### Answer by username_1 on 2019-06-27. Score: 2 | Accepted answer

I am not sure if i get what you mean, do you want to have the categories as content blocks, which show the entries ordered by last updated, but the category blocks should be ordered as well e.g. if entry x in categort y is the newest the category block y should be on top of the list?
Otherwise that should work, displaying the latest 10 updated entries on top for 8 categories all in descending order relative the the update date
   {% set categories = craft.categories({
         level: 1,
         limit: 8,
         orderBy: 'dateUpdated desc',
     }) 
  %}

  {% set offers = craft.entries({
     relatedTo: categories,
     with: ['offerLogo'],
     limit: 10,
     orderBy: 'dateUpdated desc',
     }) 
   %}

   {% for offer in offers %}
      {% include '_card' %}
   {% endfor %}


---

