Query Posts Ordered By Author Last Name

This is untried and taken from Stack Exchange: http://stackoverflow.com/a/22056861/2821561

<pre><code>$args = array('posts_per_page' => '-1','order' => 'ASC', 'orderby' => 'author');
$cat_posts = get_posts($args);
$options = array();

foreach ($cat_posts as $cat_post) :
    if (!in_array($cat_post->post_author,$author_array)) {
        $author_array[] = $cat_post->post_author;
    }
endforeach;

foreach ($author_array as $author) :
    $auth = get_userdata($author)->display_name;
    $nicename = get_userdata($author)->user_nicename;
    $lastname = get_userdata($author)->last_name;
    $options[ $lastname ][] = '<option value="/author/'.$nicename.'">' . $auth . '</option>';
endforeach;
ksort($options);
foreach ($options as $key => $option) {
    foreach( $option as $k => $v ){
      echo $v;
    }
}</code></pre>

Revisions

Tags: ,

No comments yet.

Leave a Reply