I have both regular blog posts and a custom post type in a blog. The page template shows the author posts link. If you click on that link for an author that has authored some posts, that page (blog/authors/mr-author) shows the expected bio information and a list of the author’s posts.

However, if you create a user that is an author, but who has only authored the custom post type, and no regular posts, the link generated by the_author_posts_link() (which is still the correct link: blog/authors/mr-author) shows an unpopulated page (ie: the fields are all empty, and the posts listing is the full list of all posts for all authors).

Clearly, we’re not getting the right data inside the $authordata global. But why? author.php is using standard template tags like get_the_author_meta('display_name') to display author information, but this is all showing blank results for an author that has no posts.

I’m currently digging through core to figure out where and when $authordata gets populated to see if it’s linked to a specific post type being present, but so far have yielded nothing useful. Anyone run into this before?

EDIT: SOLUTION BASED ON CHIP’S ANSWER

add_action('pre_get_posts', 'hdb_add_custom_type_to_query');

function hdb_add_custom_type_to_query( $notused ){
     if (! is_admin() ){
        global $wp_query;
        if ( is_author() || is_home() ){
            $wp_query->set( 'post_type',  array( 'post', CUSTOM_TYPE ) );
        }
     }
}

Assumes you’ve defined CUSTOM_TYPE constant at some point, probably when you declare the custom post type.

5 s
5

I believe the issue is that the default query only queries for post post-type. (See related WPSE question here.)

So, you probably need to modify the query in your author.php template file, so that all relevant post-types are included in the query.

Leave a Reply

Your email address will not be published. Required fields are marked *