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
- How to limit the number of posts that WP_Query gets?
- Should we trust the post globals?
- Get the ID of the latest post
- How to make comments work for a post loaded per Ajax?
- How to show related posts by category
- Random sort within an already sorted query
- get_children() Not Working with orderby Parameter
- How to get all posts related to particular category name?
- get all posts ID from a category
- Allow variable amount of comments before pagination
- how to get a different html for odd/even posts?
- How to display posts by current user/author in a custom page template?
- Using $wpdb to query posts with meta value containing current post_id
- Query posts from current year
- How to display comments and comment form on custom post type?
- How to get previous 10 days post from a specific date – WP Query
- Comments are assigned to wrong or related post
- 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?
- Update post date on every new comment?
- I have over 4000 posts, will querying some of them cause performance issues?
- Duplicate posts
- Show the title of the latest post by author
- Looping through posts per category gives same posts for each category
- How to show posts rank based on custom field value
- Setting pagination for images attached to a post
- Query only Posts from Both of Two Category?
- One comment per user email per post
- Can’t show comments count per post outside loop
- is there a better way of combining this?
- How do I create Comma Separated list of attached image ids?
- How to add posts to wp_query result?
- Only display posts with comments
- 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
- How to output comments number of a post per day?
- Enable commenting on front-end preview page for pending posts
- Order post by year DESC and month ASC
- Hide comments awaiting moderation from user who submitted the comments
- WordPress get posts by date without query_posts
- Should ‘setup_postdata()’ be reset with ‘wp_reset_postdata()’?
- How can I display a specific user’s first published post?
- Query All users that has post
- wp_enqueue_media() slows down my WP site
- How can I get all posts data from within a paginated search result?
- Hide Post comments when displayed via WP_Query
- Including new Javascript only after a comment is made
- Search query – exact post title match
- Disable Post/Page comment emails for creators
- Sorting posts alphabetical that have single digits
- Posts are not showing up on particular category
- Query posts from different categories in multisite
- Display posts with comments closed, with pagination?
- get selected post using $_GET
- Check if post exists
- posts_per_page doesnt work
- How Can i Get 5 Recent Post Title With Corresponding Link?
- Sorting posts according to view counts not working
- 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
- Can I set and show “important” post in my blog?
- setup_postdata doesn`t seem ot be working
- Only display posts after current date
- Get posts by multiple ID’s (query)
- How to start with post number x?
- Exclude posts with empty post_content in wp_query
- When trashing a post, also trash related comments
- 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
- Encrypt / Decrypt Post Title and Details
- Get Posts via Taxonomy Term Name with Space
- Get specific posts by ID in wordpress
- Improving WP_Query for performance when random posts are ordered
- Should $found_posts be returned as string in ‘found_posts’ filter hook?
- Posts vs. Pages
- Automatically republish old posts
- count the total number of comments the user has received for his published posts
- get_next_post() and get_previous_post() return wrong posts
- Query how many items to show in shortcode
- How to Orderby Comments by post title?
- WP_Query Authors OR Categories
- Get Posts that are in the current month or later
- Inserting custom data to the_post() during loop
- How do I restart my loop with get_next_post()?
- Sticky post appears twice