The easiest way is by using custom MySQL query with WPDB
class.
global $wpdb;
$table = $wpdb->prefix . 'posts';
$sql = "SELECT DATE(post_date) AS date, COUNT(ID) AS count
FROM {$table} WHERE post_type="my_post_type" AND post_status="publish" GROUP BY DATE(post_date)";
$rows = $wpdb->get_results($sql);
Or if you want to prevent SQL injection, you can use prepared statement like this:
global $wpdb;
$sql = $wpdb->prepare(
"SELECT DATE(post_date) AS date, COUNT(ID) AS count
FROM %s WHERE post_type = %s AND post_status="publish" GROUP BY DATE(post_date)",
array(
$wpdb->prefix . 'posts',
'my_post_type'
)
);
$rows = $wpdb->get_results($sql);
Then you can iterate the $rows
to show the data.
foreach ($rows as $row) {
echo $row->date . ' -- ' . $row->count;
}
Related Posts:
- How do I create a link that will always show the latest post?
- What is the difference between “post” and “page” in WordPress?
- Understand post type
- how to get random post id by using post type
- why there are so many posts whoes post_type is revision? will these records waste too much database space?
- Post type no single page
- Target only single product page
- Woocommerce – custom post type of checkout page
- Taxonomy Category category.php not working
- How can I get the first post THIS SAME CATEGORY?
- How do i retrive a post from a custom post type
- How to get only post=’product’
- Find the post an attachment is attached to
- Skipping first 3 posts in wp query
- How to add metabox for post of specific category
- How can you make sure authors’ posts are longer than 250 words?
- Is there any way of copy/pasting, duplicating, or auto-generating posts for fast testing?
- How to get a post content from another wordpress blog/site?
- Post from front-end only by logged in users, form posts as “posted by:
- How can I group posts by date on frontpage?
- WordPress Child Category Display All Posts
- Hide comments awaiting moderation from user who submitted the comments
- Sanitizing `wp_editor();` Values for Database, Edit, and Display
- How to display sorted posts in the ‘All Posts’ page
- Changing my permalink structure – will new layout conflict with existing page?
- WordPress blog posts api – get posts by author
- Sorting posts according to the term they belong to
- Sorting posts according to view counts not working
- Get post excerpt and title by specific post ID?
- Count total number across post types
- Related posts loop based on tags AND categories doesn’t work without at least one tag assigned
- get current post id inside hook
- Display all posts that were published before full post on single.php
- How to make number of blog posts a custom field?
- check if wordpress is updating or publishing a post
- WordPress blog or WordPress website
- List blocks created by a specific block plugin
- Sort WP posts by span value
- Add Read More Tag to a post content (Single.php)
- How to compare two posts including their meta fields on a scalable base?
- Why does my site often display 404 on subpages?
- Move comments only from one WP installation to another
- How to change the color theme per post?
- Copy post to separate database with “add_action(….)”
- How to create a template for Pages?
- Do all wordpress themes a similar class name for content?
- Display Notification Bar on Header on Certain Post Count
- How do I do a page break?
- Add a variable in a post
- Loop parent terms {display posts} AND loop child terms {display posts}
- Print out last 3 blogposts
- Is there a query string for edit.php to show all posts that have no custom taxonomy terms?
- Is it possible to add a shortcode below post title?
- Edit the post title from the frontend
- Edit post locked notification dialog on edit post screen (post.php)… hook maybe?
- wp_posts table extremely large
- Image behind the post’s title
- Get the most recently modified post date of most recently modified post
- Only allow posts with a specific term to only be viewed by other authors with the same term in their post
- Queries take 120+ seconds on my large WordPress site
- How to limit author related post listing ?
- Get all custom posts with a certain taxonomy
- How do I display the post_title with get_permalink?
- inserting a category into post
- Limiting the amount of posts retrieved by the loop
- Getting posts from some categories plus some individual posts
- Change layout of post depending on category
- Insert specific information to a posts of a predefined category
- Direct some posts to only appear on a specific page
- How To import post If I have only subscriber access
- Get post publishing date from within custom HTML block
- Adding Text after Post Title based on Category using IF Condition – But not for menu items
- Updates are not showing to public (New Posts , Theme Change)
- How to bulk Update URLs to new values?
- How can I make a post sub link?
- How do you change the permalink for posts for a single category?
- post thumbnails error
- Excluding category from post navigation in WordPress?
- Add another feature image box
- Change archive results based on GET request
- Let Contributors Review only (Not Publish) Others Posts
- Change Custom Post Type to Post + Category
- Querying posts from current category, using a variable as array argument
- How to show view all posts from front page?
- Ajax the create and edit post form into lightbox and get results
- Wp_query loop is not working as it should
- Blank page after changing number of post displayed in wp-admin
- Precedence of page permalinks over woocommerce product category links?
- How to create a Top 10 Popular Posts Page?
- Related posts not working in the index
- Add category selection to function request
- Correcting the content width when sidebar is inactive?
- 404 error on every post and page other than home
- Successive creation of over 1000 posts causes 404?
- Category pages vs single post pages
- How to limit post query to only return a total count of items with certain post statuses?
- Redirect posts to sub domain except pages
- How do we display a certain category type on a page while hiding all others?
- Action while post is being published
- Do anything on post_status change [duplicate]