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

Mike Schinkel mikeschinkel at newclarity.net
Wed Aug 11 17:04:30 UTC 2010


On Aug 11, 2010, at 11:06 AM, Simon Blackbourn wrote:
> 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;
> }

Yes, that is another great option! (assuming the client only needs one sort order.)

-Mike


More information about the wp-hackers mailing list