Depending on your needs, WP Query may not work for this since it won’t include posts that have been deleted after the trash has been emptied. This should work (but hasn’t been tested):
function wpse_custom_post_type_counter() {
$number = get_option( 'wpse_custom_counter' ) ? absint( get_option( 'wpse_custom_counter' ) ): 0;
$number++;
update_option( 'wpse_custom_counter', $number );
}
add_action( 'publish_your_custom_post_type', 'wpse_custom_post_type_counter' );
You’ll need to update the function and option names to suit your application. Also the slug for your custom post type should replace your_custom_post_type
in the call to add_action
.
One disadvantage of this approach is that it will only work going forward, it won’t be able to count existing posts.
Hope that helps!
Related Posts:
- How to mark every 3rd post
- Count posts within a custom post type and specific taxonomy and terms?
- How to Display a List of Users Who Have Made at Least 1 Post?
- How to Display Network Post Count?
- How to cache a shortcode functions output?
- Count posts in category including child categories
- Count singular post views automatically
- Set font size automatically according to number of words in post
- Network wide post count (WP Multisite)
- Redirect based on user post count
- Alternate custom content in the loop
- Show that current post is number X out of X
- Show the author’s count of total amount of posts assign to a custom taxonomy term
- Double count view in archive.php
- Count to how many categories a post belongs to
- Count total number across post types
- Count search results in heading
- How to hide first gallery for every post?
- Display Published Posts Count for Certain Time Period
- How can I get global $post to work for CPT and update user?
- Display Notification Bar on Header on Certain Post Count
- Show posts count for Categories and Tags in wp_nav_menu
- How to add category post count in main navigation menu [closed]
- Count number of posts of current month
- Howto show comment count by post in post?
- Counter is skipping post when I still want it visible [closed]
- Count several post tags
- Get post number both in the loop and in the post
- How do I insert a after every 5 posts in a WordPress Loop that infinitely loads posts?
- Count the number of a post types associated with another post type
- Echo the number of posts being displayed
- Display amount of pending posts in back/front end
- Count user posts and store the number for later use
- why the posts queried from sql is more than those showed on the page?
- Count the total views of all user posts published
- Author post count in category
- Set post title font size automatically according to number of words in post title
- Show post count in custom taxonomy page
- Count singular post views automatically
- How to count posts in tags within time limit
- Display Custom Post Category Count & WordPress Category Count Using Shortcode
- Counting Posts by Category
- Display number of post published every day
- Retrieve posts inside foundation tabs and tab-content split by 3 per row
- Alternative content between posts no repetition
- count_posts to a standalone link
- How to control Post view count incresing in sidebar widget posts too?
- How to mark every 3rd post
- Add a minimum word count to Excerpt (and how to force Excerpt as a rule for WyPiekacz)
- How to limit the number of posts a user can publish based on user type
- ho can I get the number of the current post instead of the post id?
- post_count not working
- Adding Count Post in Page
- Count words for all posts by all authors
- Word count for all posts of all authors
- Display post count on archive page in reverse order
- How to check if post meta key exists or not in wordpress database
- Custom Post Types, slug, archive and SEO plugins
- Portable Post Links
- Related Posts by Multiple Tags?
- Action hook ‘wp’ firing twice… why?
- How can I display 7 posts on the home page, but 9 posts on the subsequent pages?
- WP REST API, query total posts in a category
- 404 error after publishing a post
- How to remove_filter that filters iframes in posts? [duplicate]
- Showing Thumbnail from Previous and Next Posts
- WP rest api returns 404 only when author param is used
- What Is meta_id In wp_postmeta?
- the_posts filter been called multiple time
- Reset/Reorder posts ID in the MySQL wp_posts table
- Apply a style for 4 blogs and another style for the next 4 blogs in wordpress blog page?
- Blank page when saving edits on post
- Listing Specific Categories from Current Post with Depth
- Custom Post Type Rewrite To Include Parent Page(s)
- outputting posts’ taxonomies: cant get ‘get_the_taxonomies’ working
- Query for first 3 posts to change the look and feel
- Getting blog pagination to work on page set as front page
- Is there a way getting post fields using `transition_post_status`
- Get featured image on hover of post title [closed]
- How get top post view for today for today post
- Changing wp_link_pages() to “Next Page” and “Previous Page” buttons?
- Why my meta boxes won’t show in front post page?
- Authors’ Links on Homepage Not Going to Author Post Pages
- Display Current Posts Category (with the most posts)?
- How can I add random alphabets in wordpress permalink posts structure
- Filter posts by month (dropdown)
- Redirect old Posts URL to new URL
- Use posts from old db by changing prefix
- Override default post type ‘post’
- ‘posts’ table should not store the absolute image path
- How can I alternate styling of images in a post? [closed]
- Display iframe or embeded posts on homepage
- How can I use the “Your latest posts” as a template?
- Query to get data of a post, if in category?
- Order posts by custom field
- Continuous listing from a custom field
- Add class name of content, Hypernate doesn’t work to IE and Chrome
- Issue with wordpress pagination: last 2 posts show again on second page
- Extra Theme – Fit image inside of Featured Post Slider
- How can I show the positive and negative comments for a same post separately?