I have a custom post type “Publications” and a custom author role “Writers.” The publication post shows the correct writer but when I go to the author page (mysite.com/author/writer-name), the page doesn’t show the writer’s publications. I think this is the relevant code in the author-header.php file
<span class="td-author-post-count">
<?php echo count_user_posts($part_cur_auth_obj->ID). ' ' . __td('POSTS');?>
</span>
I thought “POSTS” should cover CPTs as well, so I don’t know why the count for posts for the author/writer would show 0. Any ideas?
Hello,
please try this solution (add this in functions.php and modify the name-of-post-type-here to your custom post type name):
function custom_post_author_archive( &$query )
{
if ( $query->is_author )
$query->set( 'post_type', 'name-of-post-type-here' );
remove_action( 'pre_get_posts', 'custom_post_author_archive' ); // run once!
}
add_action( 'pre_get_posts', 'custom_post_author_archive' );
I did try that. In fact I tried it in several places but it doesn’t work anywhere. One thing I wanted to confirm. Should the name of the custom post type entered in the function be exactly the same as what is entered under the field “slug” in Types? I’ve been looking all over to confirm actual name of the CPT per Types and I think this is it. If so, the function isn’t working.
Hello,
I don’t think that the post type slug should be put in there. It should be the post type name that is here in the register post type function: http://screencast.com/t/4V4CFbc51kb
Sorry for letting you down on this. We did not work a lot with custom post types đ
Sorry, you weren’t the right person to ask about the CPT name. I’m using the Types plugin (part of Toolset) to create custom post types and I’m not sure where they store the function so that I can confirm the name. I’m pretty sure I’m using the right one but will confirm and then go back to the issue of pulling author posts for a custom post types. It’s a critical issue for the site, so I’ll have to figure out something.
I’ve been working on this some more and have created a custom template for the Publication detail page. Most of it seems to be working except the variable part_cur_auth_obj isn’t returning any results. For example, this
<?php echo $part_cur_auth_obj->display_name; ?>
and this
<?php echo $part_cur_auth_obj->description; ?>
return no results (are blank).
I tried adding $part_cur_auth_obj as a global to the top of the page, but that didn’t have any effect. If I knew more PHP, I’d probably be able to see the reason this isn’t working, but I don’t. Any chance you could point me in the right direction?
PS. I added this to the custom template (based off single.php), towards the top:
//read the current author object - used by here in title and by /parts/author-header.php
$part_cur_auth_obj = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
`
I thought that would do it but I’m still not getting results as in the previous examples.
