Page 1 of 1
Forum

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!



WordPress - get_pos...
 
Share:
Notifications
Clear all

[Solved] WordPress - get_posts order by custom field

2 Posts
1 Users
0 Reactions
1,484 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

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.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

Even vergeten de referentie pagina van de WordPress codex te plaatsen: get_posts.


   
ReplyQuote
Share: