I am trying to fetch all the posts that are commented on last 24 hours range.
What I have tried is:
global $wpdb;
$results = $wpdb->get_results( "SELECT comment_post_ID FROM wp_comments WHERE comment_date > '" . date('Y-m-d H:i:s', strtotime('-24 hours')) . "'", OBJECT );
But from above query I am getting all the posts whose comment date is greater than todays datetime. I want to fetch post which are commented under 24 hours.
Can anybody help me in this. Any help would be appreciated..:)
Thanks in advance.
Take this . First one will give current datetime and second one will give 24 hours back time that is past day with the same time
so you query should be like :