• Resolved adambundy

    (@adambundy)


    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)
  • this was almost perfect. I installed it into the theme Im working on. but when I click on the admin’s posts it works great but whenever It’s an author post the single page breaks. Here is the page. I have no clue what im doing wrong.

    okay… nevermind. it had absolutely nothing to do with your code. THANKS A MILLION!

    I wanted the custom post type to show up on the regular author page. Here’s what I came up with in case anyone else is looking:

    add_filter('posts_where', 'include_for_author');
        function include_for_author($where){
            if(is_author())
                $where = str_replace(".post_type = 'post'", ".post_type in ('post', 'my_custom_post_type')", $where);
    
            return $where;
        }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Authors page for custom post type’ is closed to new replies.