All parameters for “orderby” in WordPress posts

All parameters for “orderby” in WordPress posts

There comes a time in WordPress when you need to sort the wordpress posts in different order than the default one. In wordpress the default “orderby” parameter is the date. But of course there are several more, which you can use to display the posts in the order that you want. I am going to list all the parameters here:

none’ – No order (available with Version 2.8).

ID’ – Order by post id. Note the captialization.

author’ – Order by author.

title’ – Order by title.

name’ – Order by post name (post slug).

date’ – Order by date.

modified’ – Order by last modified date.

parent’ – Order by post/page parent id.

rand’ – Random order.

comment_count’ – Order by number of comments (available with Version 2.9).

menu_order’ – Order by Page Order. Used most often for Pages (Order field in the Edit Page Attributes box) and for Attachments (the integer fields in the Insert / Upload Media Gallery dialog), but could be used for any post type with distinct ‘menu_order’ values (they all default to 0).

meta_value’ – Note that a ‘meta_key=keyname’ must also be present in the query. Note also that the sorting will be alphabetical which is fine for strings (i.e. words), but can be unexpected for numbers (e.g. 1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, 56 as you might naturally expect).

Use ‘meta_value_num’ instead for numeric values.

meta_value_num’ – Order by numeric meta value (available with Version 2.8). Also note that a ‘meta_key=keyname’ must also be present in the query. This value allows for numerical sorting as noted above in ‘meta_value’.

post__in’ – Preserve post ID order given in the post__in array (available with Version 3.5).

Note: This parameters work for wordpress posts and as well for custom post types in wordpress.

Leave a reply

0
Connecting
Please wait...
Send a message

Sorry, we aren't online at the moment. Leave a message.

Your name
* Email
* Describe your issue
Chat now

Need more help? Save time by starting your support request online.

Your name
* Email
* Describe your issue
We're online! Ask us anything!
Feedback

Help us help you better! Feel free to leave us any additional feedback.

How do you rate our support?