I'm trying to create a custom version of the wp_list_authors function that includes custom post types

I’m trying to create a custom version of the wp_list_authors function that includes custom post types. I have 3 authors on the site I’m working on (www.healthyeatingadventure.org). Two of them only post regular blog posts and the third only posts recipes which is a cutom post type I created because I wanted it to have a unique layout.

I’m working on a custom plugin that will list the authors in a sidebar widget and will link their names to their posts (whether the post type is post, event or recipe). I want to clone the wp_list_authors function in wp-includes/author-template.php to create a custom function called hea_list_authors that serves the same purpose but will include the other 2 post types I mentioned. Then I’ll call that function in my plugin and the world will be a wonderful place :).

However, while I’m getting better at MySQL and PHP, I’m still sort of a novice and am having trouble figuring out how to make this work. The source code for the wp_list_authors function is found at the link below. I’d greatly appreciate any help someone could offer with this.

wp_list_authors()

Solutions Collecting From Web of "I'm trying to create a custom version of the wp_list_authors function that includes custom post types"

Ok, so I found the solution to this problem and I thought I’d post it here for anyone else who may stumble upon this question.

Turns out I was making this much more difficult than it needed to be. I just added a simple function to the custom site plugin I created (this could also be added to your functions.php file).

function hea_cpt_author( $query )
{
    if ( $query->is_author ) {
        $query->set( 'post_type', array( 'post', 'events', 'recipe' ) );
        remove_action( 'pre_get_posts', 'custom_post_author_archive' );
    }
}
add_action( 'pre_get_posts', 'hea_cpt_author' );

The hea_cpt_author portion can be whatever you want to name your function.