Support » Fixing WordPress » Show posts organized by Author

  • Resolved Kevin Kwok

    (@queesy)


    Basically I want one page that shows posts from all authors in alphabetical order, but the posts would be grouped by author.

    example:

    Amanda :
    full post 3
    full post 2
    full post 1

    Bob:
    full post 3
    full post 2
    full post 1

    is this possible? I know you can show a single author’s posts, but im not sure where to go from here. any help would be most appreciated

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    //displays all users (sorted by display_name) that are post authors with their avatar and their posts (titles)
    $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();
      }
    }
    ?>

    Michael! This was amazing, I just have to tweak it a little but thank you! Will let you know of the final results.

    Once again you have saved the day.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show posts organized by Author’ is closed to new replies.