Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] WordPress - get_posts order by custom field
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
July 5, 2013 5:43 AM
For those who use custom fields in their posts in their posts, how do you sort posts by those custom fields?
For example, here at Tweaking4All I used 2 custom fields: ShortTitle and ShortText.
I use them in the menu tree in the sidebar on the left so that I can use full-size titles and descriptions for the regular articles, but short titles and descriptions in the menu tree.
If you have only one custom field simply add to the "query".
orderby=meta_value
If you have multiple custom fields then you can specify which one to use, for example:
get_posts('meta_key=ShortTitle&orderby=meta_value');
Note: when adding the "meta_key=" you will limit the output to the posts that actually have this field defined.
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
July 5, 2013 5:48 AM
Even vergeten de referentie pagina van de WordPress codex te plaatsen: get_posts.