WordPress.org

Ready to get started?Download WordPress

Forums

How to display amount of comments per day? (2 posts)

  1. 1BJK903
    Member
    Posted 1 year ago #

    Hi all,

    I want to show the comments users make per day. So let's say I have a post, which I have written ten days ago... I want to show both the total amount of comments, but also, how much comments they have made today. So if they made 10 comments today, that has to be shown. The next day, this amount will be gone...

    How can I pull this off?

  2. sliceofpie
    Member
    Posted 1 year ago #

    You could do a custom MySQL query based on the current post's ID:

    $comments_today =
    	$wpdb->get_var(
    		"SELECT count(*)
    		 FROM $wpdb->comments
    		 WHERE $wpdb->comments.comment_post_ID = ".$post->ID."
    		 AND DATE($wpdb->comments.comment_date) = CURDATE() "
            );
    
    echo $comments_today;

Topic Closed

This topic has been closed to new replies.

About this Topic