0

On my theme author.php page I have a number of posts displayed but it only count posts of the type 'post', I need it to count multiple post types.

I think they are trying to make this core but no updates for a while, see the ticket #32243.

I'm not a coder so I don't really know how to make it, can someone help me?

  • Can you post the relevant code from your theme? What multiple post types? – birgire Mar 26 '16 at 1:32
4

This ticket was fixed and closed in version 4.3.

Make sure you got the latest version ( currently 4.4.2 )

If we check out the inline documentation for the count_user_posts() we find this part:

* @since 4.3.0 Added `$public_only` argument. Added the ability to pass an array
*              of post types to `$post_type`.

Note the default post type for that function is post.

So you will most likely have to add the post types you want, here's an example:

echo count_user_posts( 
    $userid = 1, 
    $post_type = [ 'post', 'page' ], 
    $public_only = false 
);

to get the count for the user with user id as 1 and post types post and page.

  • Thanks this did it! i just couldn't find a codex that explain the usage like you did. it maybe there isn't one yet – laura Lalas Mar 26 '16 at 13:05
  • Glad to hear it worked for you @lauraLalas – birgire Mar 26 '16 at 13:09

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.