How can i achive that?
I found count_user_posts and get_users, but how would I merge them into the desired result? Do I really have to use a WP DB Query?
2 comments
Comments are closed.
How can i achive that?
I found count_user_posts and get_users, but how would I merge them into the desired result? Do I really have to use a WP DB Query?
Comments are closed.
For now
post_type
support is not currently available forcount_user_posts()
,so put the below code in theme’s functions.php file.
Now this function would take
user id
andpost_type
as parameterpost_type='post'
being the default and gets the count of post for that user for the concerned post_typeYou can verify it by echoing the below where you need to check the post count by the user.
You can do the same for the custom post type. Now you need to get the user ids and pass through this function and display the name of the authors having 1 or more posts
or
You can add the below code where you want to display the list of users with one or more post
The above code lists all the users with one or more posts published of
post_type
post
.Very old query but still there are no direct methods to get all authors with at least one post of ‘custom post type’. WP_User_Query also does not support the post type. Using $wpdb will solve the issue.
Code:
You just need to assign
$post_type
with your post type.