WordPress.org

Ready to get started?Download WordPress

Plugin Directory

!This plugin hasn't been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

Post Sorting Reloaded

Allows sorting of posts by title, comment count, and other criteria for various pages, including category pages, tag pages, home page, etc.

Can I sort by custom fields?

Yes and no. In order to sort by custom fields, you also need to use the posts_join filter in addition to the posts_orderby filter.

For the posts_orderby filter you can use the plugin, but for the posts_join filter, you're going to have to write the code yourself.

Just add the following code either in your theme's functions.php or in a new little plugin:

add_filter('posts_join', 'my_posts_join');

function my_posts_join($join){
    global $wpdb;
    $join .= " LEFT JOIN $wpdb->postmeta wpmeta ON ($wpdb->posts.ID = wpmeta.post_id AND wpmeta.meta_key = 'price')";
    return $join;
}

Replace 'price' with whatever your custom field is called.

Now you have access to your custom field by using wpmeta.meta_value as your Sort Type.

Of course, if you need the numerical value of your custom field, you can use something like ABS(wpmeta.meta_value).

Requires: 3.0.1 or higher
Compatible up to: 3.3.2
Last Updated: 2011-8-31
Downloads: 7,735

Ratings

4 stars
4.4 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,2,2 100,4,4 100,1,1 100,1,1
100,1,1
100,1,1
100,3,3
100,1,1
100,1,1
100,4,4
100,1,1
100,1,1
0,1,0
100,2,2
100,1,1
100,1,1
100,1,1