OK, so there are some problems with your code…
-
Your SQL isn’t very safe. It would be much nicer, if you used prepare method:
$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_author = %d AND post_type = %s AND post_status = %s", $curauth->ID, 'post', 'publish' ) );
-
You clearly say, that you want to count only posts
post_type="post"
is the part that is responsible for that. So just remove that part or modify it according to your needs. -
Be careful counting different post types – remember that attachment (and so on) is also a post type.
-
Use built in functions. It would be much nicer to use
count_user_posts
.<?php $curauth = $wp_query->get_queried_object(); ?> <h2>Post Count: <?php echo count_user_posts( $curauth->ID, 'post_type' ); ?></h2>
Related Posts:
- Is there a way to get N number of WYSIWYG editors in a custom post type?
- Getting the IDs of a custom post type
- Multiple custom post types under one admin menu
- CPT Template Not Showing – Getting 404
- How to throw error to user when saving post
- Display text if current user has written 1 or more posts in a custom post type
- Pull Two Posts Into Custom Post Type `single-cpt.php`
- Count post that have specific meta value
- Remove date and category filters when editing custom post types
- Display all custom post types in archives.php
- Compare 3 custom fields and sort by oldest
- How to select one major category (or custom taxonomy) for a custom post type?
- Custom taxonomy & post slug permalink
- how to use two permalinks for one custom post type
- Adding capabilities to default roles
- How to add page attribute “Template” to custom post
- Child and grandchild taxonomy listings – 404
- Filters post in admin with dropdown select, custom post type
- Custom Permalink Tag breaks Pagination
- Display posts if a custom field value is equal to another custom field value
- Add the current menu item CSS class to a custom page type archive in WordPress menu
- Remove default post types on all sites except primary blog. WPMU
- Why is archive.php used for my page
- next_post_link on custom taxonomy
- Using several custom fields as custom post title
- Why is my Custom Post Type not showing up after adding capabilities?
- Create Template for Custom Post Type same like for Page
- Return the thumbnail meta data for getter and setter
- Page vs Custom Post Types Differences/Issues
- WordPress custom post – add dynamically meta boxes
- Roles for Custom Post Types
- Having unique constraints for custom fields in a custom post type
- Make parts of your wordpress website completely built with data from external APIs?
- JS innerhtml changing style when using AJAX
- How do I add a custom screen for a custom post type to be called from custom post row action?
- Custom post type suppress transition from future to publish
- Add Custom Post type menu to another menu in specific location
- Filter hierarchical custom post type admin page by parent, and include children & grandchildren
- How to list custom taxonomies in the back end
- Limit Search to Post Type With Apostrophe return search not found
- Specific routing for CPT
- Add a custom text to admin footer in a Custom Post Type page
- Trying to Create a PHP Variable for post_type that can be referenced Site Wide
- Custom Rewrite Rule for Custom Post Type with URL Param
- Displaying a Custom post type per day
- Setting Post Title via Meta Data returns Auto-draft
- Not sure why this template for custom post type posts isn’t displaying anything. What’s missing?
- category list with cutom post count
- I want to know if i can add two different custom post types to my wordpress site
- Run shortcode in custom script in wp_head if post type is CPT ‘Jobs’
- Custom permalink not working and showing 404 page not error
- Custom sidebar for custom post type
- How to add new post using a form to categories when categories are using as menu
- Custom wordpress loop
- page template with custom post type loop case page duplication
- adding read more link for custom post type
- ACF Relationship Posts how to show additional content
- Display 3 recent posts from one taxonomy
- Display next 3 posts based on custom taxonomy
- WordPress custom posts and permalinks
- Display latest post of taxonomy
- Translate website without duplicate custom post
- How To Read Read Custom Post Type Data in Headless CMS Mode
- Set Post Private if no linked Post Objects (ACF)
- Show in an entry a Custom Post Type associated to a post
- WordPress shows after migration
- How to display custom field in product description?
- Show code dependant on CPT & category
- Add custom template ‘sub-page’ to Custom Post type?
- WordPress Custom Taxonomy – If not parent term
- WP_List_Table Inside Metabox Not Working on Clicking Search Button
- SEARCH QUERIES – REVERSE OUTPUT
- Need folder for CPT templates for eg: single-{post_type}.php
- Subset of Custom Post Type From Admin Menu Based on Meta Data
- Media is not showing on post page
- Add an array as post content dynamically
- How to save post_status using action save_post?
- Edit custom post type page with ACF repeater fields throws ‘Service Unavailable’ error
- Redirect sub-page URLs to parent without changing URL
- Filter Term By Parent Term – Custom Post Type
- How To Loop Through list with Custom Post Types
- How to decouple custom post types components from template?
- Custom post type cannot access child page
- Customizing a plugin function using a hook
- Changing custom post_type when publishing
- erase post excerpt limitation [×]
- Show custom post type in archive page by category
- Pop up showing same content on all posts display.
- Collection of fields in a single post
- Display and Allow users to edit their own profiles
- Get result from Custom Field in Custom Post type
- Building a List of Posts grouped by custom taxonomy as the section header only to be displayed if at least one post is in that tax
- WordPress custom post type post and category links 404
- Count of posts with meta_key filled in?
- Are custom posts included when getting a categories’ posts?
- How to get lowest price from custom fields of posts
- 404 Error On Custom Taxonomy Pages 2, 3, etc
- Default WordPress Query for a Specific Custom Post Type URL
- using jetbooking for multiple custom post types
- Custom post type pagination conflict result in 404