WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 2 years ago

#31677 reopened defect (bug)

count_user_posts is not working in wordpress 4.1

Reported by: stark.manish Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.1
Component: Posts, Post Types Keywords: reporter-feedback needs-testing
Focuses: Cc:
PR Number:

Description

count_user_posts have two parameters.

  1. User ID
  2. Post Type.

There is a note in codex - Note : Since 4.1 it supports post types.

But when I am using this function in my recent wordpress version i.e. 4.1 it is not giving me proper output.

Codex Url - http://codex.wordpress.org/Function_Reference/count_user_posts

Change History (6)

#1 @boonebgorges
5 years ago

  • Component changed from General to Posts, Post Types
  • Keywords reporter-feedback added

stark.manish - Can you please give additional details? Exactly how are you calling count_user_posts()? What do you expect to get as a return value? And what are you in fact getting?

#2 @SergeyBiryukov
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

No feedback in 5 months. Feel free to reopen with more information if there's still an issue.

#3 @jberculo
2 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

I am having problems too. The function is accepting a second parameter, but it seems to ignore it. I am calling the function as follows:

<?php
echo count_user_posts($author_id, $post_type);

This always results in the amount of posts for the default post type being returned, instead of the actual count for the supplied post type.

I am using Wordpress 4.8

#4 @SergeyBiryukov
2 years ago

  • Milestone set to Awaiting Review

#5 @nishitlangaliya
2 years ago

  • Keywords needs-testing added

@jberculo ,@SergeyBiryukov,

<?php
echo count_user_posts($author_id, $post_type);

Works for me, I tested with echo count_user_posts('1', 'product');
it gave me perfect count for post type product. Please check for the same and let me know if i am missing.

Thanks.

#6 @nishitlangaliya
2 years ago

ignore previous comment. I tested with 4.8

Last edited 2 years ago by nishitlangaliya (previous) (diff)
Note: See TracTickets for help on using tickets.