[wp-hackers] visually sort ordering "custom post types" for end users

Simon Blackbourn piemanek at gmail.com
Wed Aug 11 15:06:48 UTC 2010

I use the existing menu_order column in the posts table to save creating yet
another meta field.

By default, this column is used for sorting pages but not posts, but if you
hook into the posts_orderby filter you can sort on this column for your
custom post type. Something like this should do the trick (might need
adjusting a bit for your case):

add_filter( 'posts_orderby', 'my_orderby' );

function my_orderby( $sql ) {

    global $wpdb, $wp_query;

    if( !is_search() && !is_single() && !is_admin() && 'shirt' ==
$wp_query->query_vars['post_type'] ) {
        return $wpdb->prefix . "menu_order ASC";

    return $sql;


For a really nice drag n drop admin interface, you can edit the My Page
Order plugin (http://wordpress.org/extend/plugins/my-page-order/) to add a
new admin page for sorting your post type. I've done this for posts in the
past, shouldn't be too much work to do it for a custom post type.


More information about the wp-hackers mailing list