This code count comments per day on all pages. I want that will count only on one page for 1 day. So my case: on a page with an ID of 1
, a user can comment with out any limit, but on a page with an ID of 2
, the same user can only comment once per day.
<?php
global $wpdb,$current_user;
$limit = 5; //this is limit per day per user
$comment_count = $wpdb->get_var( $wpdb->prepare("
SELECT count(*)
FROM wp_comments
WHERE comment_author = '%s'
AND comment_date >= DATE_SUB( NOW(), INTERVAL 1 DAY );",
$current_user->user_login
) );
if ( $comment_count < $limit ) {
comment_form();
}
else {
echo 'exceeded comments limit - '.$limit;
}