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 created a non-hierarchical custom post type and, by default, it's sorted by date published.

I know I can reorder them by Title with query_posts() in the archive template:

global $query_string;
query_posts( $query_string . '&orderby=title&order=ASC' );

but it takes another SQL query on each archive page. Is there a way to register the sort order natively, eventually to get posts sorted by title even in the admin?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Try...

add_filter("posts_orderby", "my_orderby_filter", 10, 2);

function my_orderby_filter($orderby, &$query){
    global $wpdb;
    //figure out whether you want to change the order
    if (get_query_var("post_type") == "my_post_type") {
         return "$wpdb->posts.post_title ASC";
    }
    return $orderby;
 }
share|improve this answer
    
yes, exactly what I was looking for. thanks! –  achairapart Aug 13 '11 at 11:44
add comment

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.