-1

I have multi author wordpress site and every author can publish posts from two different post types . i want to display author post count by post type in author.php . According to codex.wordpress i used this code: but it displays total post count instead of author post count.

<?php echo 'Number of posts published by user: ' . count_user_posts( $userid , "book"  ); ?>
0

Are you sure? Look at the code of this function (at the bottom of the page). It just retrieves the posts count for the user from the database. I think you misinterpreted your code.

Yes, it relies on get_posts_by_author_sql() function. But look at its code too... 6125 line. It justs adds posts types to the SQL query.

So you either misinterpreted your code (most likely), or your database structure is broken.

0

This solved

$author_id = get_queried_object_id(); //get author id
echo 'Number of posts published by user: ' . count_user_posts( $author_id , "custom-post-type"  ); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.