For comments:
function count_comments_in_period( $date_from, $date_to ){
global $wpdb;
$count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_date >= %s AND comment_date < %s ", $date_from, $date_to));
return $count;
}
Just use dates in yyyy-mm-dd
format.
For posts:
function count_posts_in_period( $date_from, $date_to ){
global $wpdb;
$count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_date >= %s AND post_date < %s ", $date_from, $date_to));
return $count;
}
Related Posts:
- get comments and get posts in loop
- How to know if get_posts() failed?
- Get posts by name and taxonomy term
- Query get post,how to add comment box
- Get all comments of author’s posts
- Why posts array is empty?
- How to give classname to post if post has no content?
- Related Posts function not working
- Merge get_comments & get_posts into a single query
- External link not showing on post but showing on comment
- Get first comment link on the post itself
- Get Posts Under Custom Taxonomy
- Get the ID of the latest post
- Random sort within an already sorted query
- get_children() Not Working with orderby Parameter
- How to get all posts related to particular category name?
- how to get a different html for odd/even posts?
- How to display posts by current user/author in a custom page template?
- WordPress Number of Posts Not Changing With posts_per_page
- How can I allow editors to leave comments on posts that have not yet been published?
- Setting pagination for images attached to a post
- Query only Posts from Both of Two Category?
- Trying to put an array into ‘post__in’ => array() query not working
- Comments enabled, but disabled at the same time
- Comments not showing in custom post type – WordPress
- Enable commenting on front-end preview page for pending posts
- Query All users that has post
- Search query – exact post title match
- Why is WordPress redirecting users to random posts after commenting?
- How to get most recent commented post above new submitted post in WordPress?
- Display page content AFTER a loop of posts
- setup_postdata doesn`t seem ot be working
- Get posts by multiple ID’s (query)
- How to start with post number x?
- Exclude posts with empty post_content in wp_query
- Only display a certain number of posts, dependent on how many posts there are available in a query
- how to find user ids of all commenters in a post
- Diplay comment date on WP_Post_Comments_List_Table
- Get Posts via Taxonomy Term Name with Space
- Get specific posts by ID in wordpress
- Should $found_posts be returned as string in ‘found_posts’ filter hook?
- Automatically republish old posts
- Query how many items to show in shortcode
- Sticky post appears twice
- How Can I Query a Specific Page From a MultiPage paginated Post
- filter RSS feed in URL
- WordPress custom Query for Posts in Category display posts multiple times
- Post Loop Missing Most Recent Post
- Customizing Comments on Posts
- How to get posts from a current post’s month?
- How to Get Posts, Including Private Ones?
- Random posts from a pool of posts
- Conditional Tag for has post [closed]
- How do you change the comment count in the back end posts list, to reflect unapproved comments, rather than all comments?
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- Let both the admin and post author update comment meta
- Can’t get full post title if there a spaces in title
- How to style archive post titles… but only those posts who have comments?
- Exclude some posts from displaying in wp_query based on some condition
- How to get post with slug and exclude categories
- How does WP decide how to display a page
- Showing recent post of category in page
- Internal linking to posts permalink fail because of spaces and stripe at postname
- get last post’s link with SQL query
- Custom Select Query – Selecting the Year?
- WordPress, custom post type and posts query help!
- How to implement a WordPress comments function?
- How to add content above footer in posts from specific category
- WordPress Query – Display 5 posts (same post type), each from a given tag
- Shortcode for Comments and Comment Boxes in Post Loop
- Ignore posts content in the posts queries for internal linking
- Remove the URL author of post on all comments
- Comments are in database, don’t show up in WordPress backend or frontend
- No comments allowed
- REST API Working for GET but not for POST?
- Fill the exclude array() in get_posts()
- AJAX load more posts not using correct category and repeating the same few posts
- How to add navigation arrows to manually slide through posts?
- How to convert return type of ‘get_posts()’ same as ‘wp_get_recent_posts()’?
- Sort Events by Venue Title – Sort Post set by related post ids
- Query post for today, if no post get the previous one
- Advanced Post Display/Pagination/Ordering
- 3rd Party Login in wordpress
- Sort post by category using HTML Select tag
- How do I paginate posts page with $wpdb?
- WP_Query retrieve custom posts but not the post showing
- How to get all post titles starting with numbers and symbols?
- Bulk Attach Or Insert Media To Post Without Opening Post Editor
- Special Query: Title, Terms, Content – %LIKE%
- Display the first post’s comments of category in comments.php template
- How to get single post by one author?
- How to display a certain template element only for posts published within certain time range?
- wordpress show category link instead of post link [closed]
- How to set value in Query Loop?
- Wp_query WooCommerce products
- posts_per_page – Repeats only first posts ‘post__in’ array
- How does WordPress add the comments and comment form to posts
- Need to show birthday of custom post type(Famous people in this case) in elementor. Date of birth set in custom fields
- Best method for comment section associated with different images?
- Change permalinks in posts via SQL