Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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)??

many thanks, zip.

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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