WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Show posts organized by Author (3 posts)

  1. Kevin Kwok
    Member
    Posted 4 years ago #

    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

  2. MichaelH
    Member
    Posted 4 years ago #

    <?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();
      }
    }
    ?>
  3. Kevin Kwok
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic