Custom post types not showing up on author page

Posted in: Newspaper
Post count: 11

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?

Post count: 780

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' );
Post count: 11

I added this function and changed the post-type name but don’t see any change. I’m not really sure what this function is supposed to do. Should I call it somewhere?

Post count: 780

The function is a wordpress action that runs automatically before the get_posts call in wp. One last thing: try to move the code in the author.php file at the beginning.

Radu from tagDiv

Post count: 11

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.

Post count: 780

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 😐

Post count: 11

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.

Post count: 11

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?

Post count: 11

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.

Post count: 27

Dear Vickster,

I’m considering buying Toolset. Does it work with the theme from TAGDIV?

Cheers,
Guenter

Post count: 4

I couldnt get it to work with it. But still working on; will keep you updated.

Viewing 11 posts - 1 through 11 (of 11 total)
The forum ‘Newspaper’ is closed to new topics and replies.