Order by meta_title doesn't seem to work

I’m using v3 of ghost. When I tried the {{#get}} helper, with order="meta_title asc", I get posts, but not in expected order. But this works with fields such as title or slug. Is this not supported?

The reason I am doing this is to overcome the lack of custom field/sortable field. Is this the right approach?


Hey @Frank_Liu :wave:

You can’t have the order like that because meta_title is not a field that’s stored in the database - it’s a helper that’s available to you in your theme


Thanks for the info. But if that’s true, how is the meta title stored? In ghost, I can change meta title to something different from the title. Can I sort on that?


Aah, totally forgot you can do that! You’re right; as of now, you’re not able to filter by the meta_title property.

/cc @DavidDarnes I think I might have found a bug or misuse (below) in the core relating to relations, should I escalate to gh?

The model base parseOrderOptions pulls in a list of permitted attributes from the child modal, including allowed relations. This allows you to set the order to one of those relations, which kind-of breaks the API request. For example, ordering by authors asc will give you a 400, but title asc works perfectly fine, and potato asc succeeds because you can’t sort by potatoes, and therefore the order is ignored.

There’s also the question of if it should be possible to sort by one of the related columns - for example, as @Frank_Liu was asking, is order="posts_meta.meta_title asc" a valid request? I know query-wise, that’s a bit more complicated, but I think it might be an unexpected regression from 2.x when the posts_meta table didn’t exist.

Here’s the error that Ghost logs:

[2020-04-09 02:28:28] ERROR "GET /ghost/api/v3/content/posts/?key=lol&order=posts_meta%20asc" 400 8ms

Could not understand request.

Error ID:

Error Code:


BadRequestError: Could not understand request.
    at new BadRequestError (.../3.13.1/node_modules/ghost-ignition/lib/errors/index.js:113:23)
    at .../3.13.1/core/server/models/plugins/pagination.js:212:27

Error: SQLITE_ERROR: no such column: posts.posts_meta

Could escalate? Thanks for debugging this. I think the original use case from @Frank_Liu is a reasonable one and is a nice method of ordering posts. Would also appreciate a link to the issue here too, thank you! :heart_decoration: