Group posts by author name in Wordpress

2Fast2BCn

New member
Joined
May 27, 2016
Messages
10
Points
0
WordPress allows us can include entries for each group separately as by subject, date, character (alphabet) or by keyword. I will share with you codes that you can list entries by author name. With this code, you can easily manage each member's posts.

Just copy the code below and paste it to anywhere that you want to display on your blog.


Code:
<?php
$blogusers = $wpdb->get_results( "SELECT ID, user_nicename from $wpdb->users WHERE 1=1 ORDER BY display_name" );
if ($blogusers) {
  foreach ($blogusers as $bloguser) {
    $user = get_userdata($bloguser->ID);
    $args=array(
      'author' => $user->ID,
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo '<p>User ID ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname . '</p>';
      echo get_avatar( $user->ID, 46 );
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
  wp_reset_query();
  }
}
?>
Hope it helps!
 
Older threads
Latest threads
Replies
0
Views
590
Replies
2
Views
789
Similar threads

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top