I'm working on a pretty complicated site where everything is managed by category type including automatic spinner image submission, etc.. Unfortunately, its doggone difficult to manage things when the admin panel "All Posts" sorts them by date (DESC) I'm thinking it sure would be handy to have the show "All Posts" in category name order.

I Found this small routine, that works for sorting by Post name.

 Plugin Name: Set Post Order In Admin
 Version: 0.1
 Plugin URI: http://wordpress.org/support/topic/336715/
 Description: In Posts->Edit, display posts in title order.
 Author: MichaelH
 Author URI: http://codex.wordpress.org/User:MichaelH/MyPlugins
 check out: http://codex.wordpress.org/Class_Reference/WP_Query
 in the section order and orderby parameters  */
 function set_post_order_in_admin( $wp_query ) {
    if ( is_admin() ) {  
         $wp_query->set( 'orderby', 'name' );
         $wp_query->set( 'order', 'ASC' );  /* ASC or DESC */
 add_filter('pre_get_posts', 'set_post_order_in_admin' );

That works okay for sorting by title, but I really need to be able to sort by category name. I tried playing with the $wp_query->set( 'meta_key', 'category' ); and $wp_query->set( 'orderby', 'meta_value' ); but when I started using those, I just got an empty return for All Posts within my admin panel. Any ideas on what is missing? I've tried a number of terms for meta_key all of them fail. Anybody been here before? Any idea on how to achieve the goal of sorting All posts in the admin panel by category (parent)??

3 Answers 3


zip, you might need to save your category as a new post meta first, that's how orderby meta_value works.

Not sure if this could help, I stumbled upon this plugin: http://wordpress.org/plugins/custom-post-order-category/, it could let you specified a category then order posts in that category.

If you're curious about how to save category into a post meta, I've used the Meta Box plugin to do so: http://wordpress.org/plugins/meta-box/. Let me know if you need further assistance.


Putting aside the objections to order by taxonomy, eloquently given by @Otto in https://wordpress.stackexchange.com/a/14309/25886, I suppose his answer has merit.

His reference to http://scribu.net/wordpress/sortable-taxonomy-columns.html in particular, with a post on sortable taxonomy columns.

The folllowing code is by @mikeschinkel:

function color_clauses_mike( $clauses, $wp_query ) {
    global $wpdb;

    if ( isset( $wp_query->query['orderby'] ) && 'color' == $wp_query->query['orderby'] ) {

        $clauses['join'] .= <<<SQL
LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
LEFT OUTER JOIN {$wpdb->terms} USING (term_id)

        $clauses['where'] .= " AND (taxonomy = 'color' OR taxonomy IS NULL)";
        $clauses['groupby'] = "object_id";
        $clauses['orderby']  = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) ";
        $clauses['orderby'] .= ( 'ASC' == strtoupper( $wp_query->get('order') ) ) ? 'ASC' : 'DESC';

    return $clauses;
add_filter( 'posts_clauses', 'color_clauses_mike', 10, 2 );

according to https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters there seems no built-in way to achieve that. however, you can go with custom-coding, like @pimSchaaf suggested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.