Authors page for custom post type
-
I just had to solve this issue and thought I’d share with the WP-iverse. Thanks to Aneesh Joseph for help with the queries!
This page will list all authors who have posts of the specified custom post type and display their name, gravatar and bio, then links to the most recent 5 posts.
<?php $authors = $wpdb->get_results("SELECT ID FROM $wpdb->users WHERE EXISTS (SELECT post_author FROM $wpdb->posts WHERE $wpdb->users.ID = $wpdb->posts.post_author AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'my_custom_post_type') ORDER BY display_name"); foreach($authors as $author) { $curauth = get_userdata(intval($author->ID)); ?> <div class="author" id="author-<?php echo $curauth->ID ?>"> <?php echo get_avatar( $curauth->user_email, '100' ); ?> <h2><?php echo $curauth->first_name; ?> <?php echo $curauth->last_name; ?></h2> <p class="authorBio"><?php echo $curauth->user_description; ?></p> <h3>Recent articles by <?php echo $curauth->first_name; ?>:</h3> <ul> <!-- Posts Loop --> <?php query_posts( array( 'post_type' => 'my_custom_post_type', 'showposts' => 5, 'author'=>$author->ID ) ); while (have_posts()) : the_post(); ?> <li><? echo $curauth->id;?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></li> <?php endwhile; ?> </ul> </div> <?php } ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Authors page for custom post type’ is closed to new replies.