WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 2 down vote accepted


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

Your Answer


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.