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 have a post type called 'article' and on the article archive page i'd like to show all the articles, sorted by author.

function kia_adjust_the_query( $query ) {

    // change posts_per_page param
    if ( is_post_type_archive( 'article' ) ) {
         set_query_var('posts_per_archive_page',-1);
         set_query_var('order','ASC');
         set_query_var('orderby','author');
    }


}
add_action('pre_get_posts', 'kia_adjust_the_query');

the above sets up the basic query adjustments. however, the blog is principally that of 1 author, say "Bob"... so ideally i'd like to pull all of the posts by Bob out into a first column for emphasis, and then continue on through the other authors.

is this possible to do during the while loop somehow or do i need 2 separate queries?

//EDIT for added complexity: i usually try to strip my questions down to the minimum, but in this case i think i went too far

my client is the sole author on his blog. however, he uses a meta field ('guest_author') and filters get_the_author to create a pen name for guest posts that he didn't actually write, without creating accounts for other users.

can i sort the author posts that are his posts (so no value in the meta field) and then, by the other authors (same author ID, but different 'guest_author' values). if this isn't possible, would the best way to approximate it be to create dummy accounts for the other authors?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You could do that with a custom posts_orderby:

add_filter( 'posts_orderby', 'wpa58715_posts_orderby' );

function wpa58715_posts_orderby( $orderby_statement ) {
    if ( is_post_type_archive( 'article' ) ) {
        global $wpdb;
        $orderby_statement = "FIELD($wpdb->posts.post_author, 42) DESC, $wpdb->posts.post_author";
        return $orderby_statement;
    }
}

Swap in your author ID for 42.

share|improve this answer
    
is there anyway to run this based on author name and not ID? or course my client would have to be difficult and and use pen-names for guest authors (stored in post meta) instead of creating other user IDs. otherwise, this does answer the question as i described it. –  helgatheviking Jul 17 '12 at 1:16
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.