I’m posting a new answer because I found this thread while searching for the same thing and the solutions here weren’t optimal.
The post_type
argument can be a string or an array of post types.
function custom_count_posts_by_author($user_id, $post_type = array('post', 'page', 'custom_post_type'))
{
$args = array(
'post_type' => $post_type,
'author' => $user_id,
'post_status' => 'publish',
'posts_per_page' => -1
);
$query = new WP_Query($args);
return $query->found_posts;
}
Related Posts:
- Query/list all terms and their custom post count
- How to make sure content doesn’t display if selection is empty
- Trying to add a class to post links
- How to count other posts not having specific taxonomy terms?
- display post count in archive page that have relation with another taxonomy term
- Complex Custom Loop with Includes
- Display all posts in a custom post type, grouped by a custom taxonomy
- Query by post title
- Get posts for custom post type with WP_Query
- WP_Query() show posts that end later than today
- How to check if a WP_Query has data
- Sorting a query by custom field date
- Number of pages – multiple (custom) post types
- Enforcing canonical URLs with multiple custom post types
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- Retrieving 3 latest post from each of 5 different custom post types
- Get latest 4 post on a custom post filtered by category
- how to group custom post type posts by custom taxonomy terms
- How to sort CPT by custom meta value (date), and return posts month by month
- Wp-query causing problems with the_content();
- wp_query and comment_parent – select only posts with top level comments
- Multiple Archive Pages for Custom Post Types AND Taxonomies
- Display children and grandchildren of a custom post type
- Getting all custom posts with a certain category
- Custom Query to display posts with custom field
- Get taxonomy description based on variable
- Custom post_type search’s $wp_query->query_vars do not correspond
- wp_query custom post type by taxonomy & standard post by taxonomy
- Query Custom Post Types & category_name?
- Conditional to modify query results
- WP_Query is printing out only one post when posts_per_page is set to multiple
- WP Query to displaying date and posts for that date?
- Use WP_Query() to Output the 4th to 6th Most Recent Posts of a Custom Post Type
- Get all Posts If has same custom field values in Posts
- Custom Post Types not showing, custom WP_Query
- WP_Query | ‘post_type’ doesn’t work
- Filter by custom taxonomy slug on a custom post type
- Sorting multiple custom post types without a meta key/value pair by sort order
- Can I create a loop with multiple post types and specify different $args for each post type?
- Display custom post type from dynamic custom field
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- wp_query check if integer exists in custom field’s array
- Custom-Posttype & Custom Taxonomy WP_Query
- orderby rand is not working for a custom post types
- Stuck in Order by more then one
- Display featured image from one CPT within another CPT query
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- How do you paginate a query grouped by month?
- Why is my category template ignoring post type?
- pagination not working for category.php (custom post types in categories)
- Query based on custom fields start and end date
- Retrieve custom post types by custom taxonomies with WP_Query
- Add ‘last’ class to second post in featured post loop
- Different Limit number of post on different archive page
- DIsplaying URL of custom field in last post of certain taxonomy && post type
- Using page slug in wp_query
- Custom taxonomy wp_query woes.
- Trouble with pagination
- Different options per post type in WP_Query
- Custom Category Walker with Image, Fallback to Most Recent Post in Category Image
- List categories, subcategories and posts from custom taxonomy and custom post type
- Custom Post type loop with ACF not displaying properly
- Sort results without WP_QUERY?
- Using Wp_Query, Json to add Highcharts series data
- Display the current post in browser as the first post in a loop (for a slideshow)
- How to query Posts from a custom post type which contains a custom taxonomy?
- filter the_content, custom post type, and wp_query
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- Get_the_term_list inexplicably adds values in foreach
- Single parent post lists child posts with pagination
- custom taxonomy pagination 404 error
- wp_query can’t get max_num_pages in custom post type
- Custom Form / Search with Custom Post Type Data
- After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel
- Query to show post current day
- Using ACF values in nested WP queries for CPT with date values in the past
- how to display posts content on the custom css popup by clicking on each title on the sidebar?
- How do I insert a custom post type query after a certain number of recent posts and then resume recent posts?
- WP_Query for custom taxonomies showing posts from non-specified terms?
- how to display new private message to users?
- Make pagination work as a carousel (custom query)
- WP_Query with all posts in one custom post type and only posts in another custom post type with a specific category
- Search result based on URL
- subtracting the current post form then whole loop, which is generating all CPT titles
- Displaying WordPress posts from post and custom post type in custom taxonomy
- Imported Content Doesnt Show Up On Frontend
- Loop carousel slider in wordpress
- Manually build WP_Query
- Loop with Custom Post Type and Taxonomies
- New WP_Query not isolating custom post types on front-page template
- How to load more custom type posts through AJAX & LOAD MORE POSTS button
- Pagination always adding “Next” link when results come from Custom Post Type WP_query
- 404 on Pages for Custom Post Type & Query_Posts
- Pagination not working on homepage
- How to query custom post then display sections by meta value
- Is it possible to make is_category() recursive?
- Get X posts with the same terms as the current post (custom post type and custom taxonomy)
- Display ACF object field data using Elementor Custom Query
- WordPress custom field sorting, weird behavior: the latest post is at the end
- Sort ACF by custom taxonomy