Since the publish date is stored, you can simply range-select count for posts, which are published in a given interval range.
function count_posts_per_interval($seconds) {
global $wpdb;
$count = (array) $wpdb->get_row($wpdb->prepare(
"select count(ID) from wp_posts where post_status="publish" and post_date between date_sub(now(), interval %d second) and now();",
$seconds
));
return (int) array_shift($count);
}
The SQL query can take day
,week
etc instead of second
, but since WordPress ships with some useful time constants, let’s keep it that way.
# Retrieve number of posts posted within last day
print_r( count_posts_per_interval( DAY_IN_SECONDS ) );
# Retrieve number of posts posted within last week
print_r( count_posts_per_interval( WEEK_IN_SECONDS ) );
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?
- Counter of posts ever posted – even deleted ones
- 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
- 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
- Portable Post Links
- Related Posts by Multiple Tags?
- 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]
- How to edit layout of a particular post format?
- Detect Post Type when publish_post is ran
- Showing Thumbnail from Previous and Next Posts
- WP_Query in functions.php overrides global $post object, even with wp_reset_query()
- WP rest api returns 404 only when author param is used
- Reset/Reorder posts ID in the MySQL wp_posts table
- How to add pagination in between post and comments?
- Posts not showing on page
- Having trouble with the_post_thumbnail to display thumbnail with custom size
- How to Programmatically add an empty Block to every post on wordpress site?
- show custom post type category dropdown sorting result on same page
- How to exclude visited posts from loop
- Number of displayed posts
- Add custom text automatically on each post
- What date to use as a post date? date_gmt or modified_date_gmt
- Display current post position in Elementor Posts widget
- My Custom Post Type Still Using index.php
- Send email for pending post
- get_posts not pulling the correct number of posts
- change the post time on multiple posts
- If custom field is empty, use one from a previous post
- How to show category based post in home page?
- YARPP php question
- Related Customs posts
- How to add a ‘News’ section to specific posts in WordPress
- I have two post types in the same query, how can I use CSS to select only one post type?
- Display post on main page with thumbnail
- index.php is only displaying current month’s posts?
- 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
- 2 tick boxes appearing below comments
- Issue with wordpress pagination: last 2 posts show again on second page
- Extra Theme – Fit image inside of Featured Post Slider
- Polylang – display one post into 3 categories with different lang [closed]
- How can I show the positive and negative comments for a same post separately?
- How to change Post title background size?