Sort query by author: 1 author, then others

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.

Read More

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?

Related posts

Leave a Reply

1 comment

  1. 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.