# Fetch posts sorted by date

**URL:** <https://forum.ghost.org/t/fetch-posts-sorted-by-date/7749>\
**Category:** Developer help\
**Created:** [June 12, 2019, 10:34am UTC](https://forum.ghost.org/t/fetch-posts-sorted-by-date/7749 "2019-06-12T10:34:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![banana\_303](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/banana_303/32/3786_2.png) [@banana\_303](https://forum.ghost.org/u/banana_303)\
**Post date:** [June 12, 2019, 10:34am UTC](https://forum.ghost.org/t/fetch-posts-sorted-by-date/7749/1 "2019-06-12T10:34:29Z")

</div>

Hey!

Api version 0.1

My query has a filter looking like this  
/ghost/api/v0.1/posts/?client\_id=xxx&client\_secret=xxx&absolute\_urls=true&include=tags&page=1&limit=10&filter=tags:[banana-blog]

But the posts returned are not ordered by published\_at, they seem ordered by random.

How can I get ordered by published\_at?

---

<div class="post-metadata">

**Author:** ![banana\_303](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/banana_303/32/3786_2.png) [@banana\_303](https://forum.ghost.org/u/banana_303)\
**Post date:** [June 12, 2019, 10:35am UTC](https://forum.ghost.org/t/fetch-posts-sorted-by-date/7749/2 "2019-06-12T10:35:35Z")

</div>

> [@banana\_303](#):
>
> client\_id=xxx&client\_secret=xxx&absolute\_urls=true&include=tags&page=1&limit=10&filter=tags:[banana-blog]

Without the filter they are returned sorted by published\_at

---

<div class="post-metadata">

**Author:** ![naz](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/naz/32/30666_2.png) [@naz](https://forum.ghost.org/u/naz)\
**Post date:** [June 12, 2019, 10:51am UTC](https://forum.ghost.org/t/fetch-posts-sorted-by-date/7749/3 "2019-06-12T10:51:20Z")

</div>

Hi @banana_303 👋 Sounds like a regression to me, will be able to have a closer look into it on Monday. In a meanwhile, could you provide a bit more context around what version of Ghost and environment/configuration you are using? Did you try running similar queries against Content/Admin v2 APIs?

---

<div class="post-metadata">

**Author:** ![banana\_303](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/banana_303/32/3786_2.png) [@banana\_303](https://forum.ghost.org/u/banana_303)\
**Post date:** [June 13, 2019, 8:11am UTC](https://forum.ghost.org/t/fetch-posts-sorted-by-date/7749/4 "2019-06-13T08:11:34Z")

</div>

Hey!

We are using a Docker container with node:10-slim  
GOSU\_VERSION 1.10  
GHOST\_CLI\_VERSION 1.9.9  
GHOST\_VERSION 2.19.1

Tried also v2 api:  
/ghost/api/v2/content/posts/?key=xxx&absolute\_urls=true&include=tags&page=1&limit=10&filter=tags:[banana-blog]

And url encoding the tags:  
/ghost/api/v2/content/posts/?key=xxx&absolute\_urls=true&include=tags&page=1&limit=10&filter=tags%3A%5Bbanana-blog%5D

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/kevin/32/32_2.png) [@Kevin](https://forum.ghost.org/u/Kevin)\
**Post date:** [June 13, 2019, 8:15am UTC](https://forum.ghost.org/t/fetch-posts-sorted-by-date/7749/5 "2019-06-13T08:15:09Z")

</div>

@banana_303 have you tried specifying an explicit order parameter? [Ghost Content API Documentation](https://docs.ghost.org/api/content/#order)

---

<div class="post-metadata">

**Author:** ![banana\_303](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/banana_303/32/3786_2.png) [@banana\_303](https://forum.ghost.org/u/banana_303)\
**Post date:** [June 13, 2019, 9:02am UTC](https://forum.ghost.org/t/fetch-posts-sorted-by-date/7749/6 "2019-06-13T09:02:33Z")

</div>

Oh, didn’t know you could add that. It works! 😃 Super, thank you!

I added this at the end of my url.  
&order=published\_at%20desc

---

<div class="post-metadata">

**Author:** ![naz](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/naz/32/30666_2.png) [@naz](https://forum.ghost.org/u/naz)\
**Post date:** [June 17, 2019, 10:55am UTC](https://forum.ghost.org/t/fetch-posts-sorted-by-date/7749/7 "2019-06-17T10:55:47Z")

</div>

After some investigation came across this issue - [Default resource ordering when performing "in" filters on related resources · Issue #10377 · TryGhost/Ghost · GitHub](https://github.com/TryGhost/Ghost/issues/10377) , so my conclusion is that that this is intended default behavior of Ghost when including filter for related object. Comes down to this line in [code](https://github.com/TryGhost/Ghost/blob/df1ba8a/core/server/models/post.js#L648).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/ghost2/original/2X/b/ba9ce5100b8bb264586f4f572545596b2ce3f081.png) [@system](https://forum.ghost.org/u/system)\
**Post date:** [July 1, 2019, 11:10am UTC](https://forum.ghost.org/t/fetch-posts-sorted-by-date/7749/8 "2019-07-01T11:10:07Z")

</div>

Closed on July 1, 2019, 11:10am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
