I'm stumped trying to order paginated entries for a channel. The end goal is to have listings with the most recent postDate at the top. The code below has the most recent item third instead of first. The first item should be third.

The same happens as you paginate to the next page. The third item listed should be the first item listed.

{% paginate craft.entries.section('podcastEpisodes').order('postDate desc').limit('3') as pageInfo, pageEntries %}
{% for entry in pageEntries  %}

{% set category = entry.topic.first() %}
    <div class="masonry__item" data-masonry-filter="{% if category %}{{ category.title }}{% endif %}">

        <p class="date">{{ entry.postDate|date('M j, Y') }}</p>

        {% set myEntry = entry.podcaster.first() %}
        {% if myEntry %}
        <p class="podcaster">{{ myEntry.title }}</p>
        {% endif %}

        <h4>{{ entry.title }}</h4>

{% endfor %}

Any idea why this is happening?

  • What happens when you try to use dateCreated instead of postDate? Oct 18 '17 at 4:51
  • Same thing happens. The most recent entry is third on list, with the third entry in the first spot (when limiting it to 3 entries per page). Oct 18 '17 at 12:23
  • Really strange, when I copy your code, remove the category and myEntry part and change podcastEpisodes to a sectionhandle of my system it works. Do you see the correct order in your backend? Maybe you could search in your database if the entries have the correct postDate there. Oct 18 '17 at 12:48
  • @Anubarak - Thank you! Your comment made me realize there was something larger going on. I found a masonry js file that was sorting entries differently than Craft. The code above is correct and working properly now that the js file was changed. Oct 18 '17 at 17:32

The code above is correct and working properly. There was a conflict with a masonry js file making the Craft ordering not work. Big thanks to @Anubarak for testing the code on their side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.