Add Custom Post Types to Author Archives Page in WordPress

This function adds custom post types to the author’s posts on the author page of a WordPress blog. In line 3 below, my custom post type is ‘skaterstatus’. Replace that with your own custom post type. You can leave in ‘post’ or remove it, depending on your needs. You can add more custom post types into the array in the same format.

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

See more:

By

We've 5 Responses

      • May 17th, 2012 at 7:04 am

        Sorry, I wasn’t very clear in my comment. I have 2 custom post types, Recipes and Photos. My goal is to have these posts types appear in my author.php page along with the standard WP posts. Adding the code snippet to my functions.php file accomplished this. But, in the WP admin, when I click Recipes from the menu instead of seeing a list of all the recipe posts, I now see a list of all Recipe and Photo posts. So the snippet must be adding the custom posts not only to the front end author page, but also to the admin backend.

        To solve this I removed the code from functions.php and added this to my author.php file:


        Right before my loop starts:

        avatar

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]