0

I'm trying to use the code below to obtain the number of custom posts the author of a post has published.

function count_user_posts_by_type( $userid, $post_type = 'artistblog' ) {
global $wpdb;

$where = get_posts_by_author_sql( $post_type, true, $userid );

$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );

return apply_filters( 'get_usernumposts', $count, $userid );

For example I'm outputting a loop of custom post types. Next to each post title I'm displaying the author of the post using a similar get_related_author function. I also want to display the number of posts this author has published. I assume I just need to replace $userid with the_author_meta() somehow but haven't managed to get it working.

Am I even approaching this in the right way?

Thanks D

1

You need to read query_posts link to do this. Here you can see 'author' - Order by author.

Simply you can do: SELECT count(ID) FROM wp_posts groupby author;

  • Thanks Manish. Sorry for the delay in the reply. Your answer helped though. – user36987 Nov 7 '13 at 14:08

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.