Fetch posts sorted by date

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?

Without the filter they are returned sorted by published_at

Hi @banana_303 :wave: 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?

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

@banana_303 have you tried specifying an explicit order parameter? Ghost Content API Documentation

1 Like

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

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

After some investigation came across this issue - Default resource ordering when performing "in" filters on related resources · Issue #10377 · TryGhost/Ghost · GitHub , 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.

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