Sorting all blog posts




I was easily able to find a way to sort my blog posts by most recently updated using sort:

{% for content in contents|sort(True, False, 'updatedDateTime') %}


However, it only sorts the posts in batches according to the pagination, I guess because of lazy loading? The first page is the 12 most recently published posts sorted by the update time, then the second page is the next 12 most recently published sorted by the update time, and so on.  I tried setting a variable before the loop, as in 

{% set sorted_contents = contents|sort(True, False, 'updatedDateTime') %}

and then pass sorted_contents into the for loop, but it didn't work. 


Is there a way to sort the entire contents array outside of pagination/lazy loading? Thanks in advance.

1 Reply 1
Recognized Expert | Partner

Hey @JKeith 

You could use the blog posts API.

Your request could sort parameter to do exactly this!


Ideally this would be returned from a serverless function so the API key isn't exposed.



This be rather simple using Vue.js!