I don't think this is a parameter in get_comments( $args ); so I'm using a SQL statement. First I obtain a comment date from a separate table I created. Afterwards, I want to retrieve all comments made after that date.
$last_updated_comment = "
SELECT comment_date FROM wp_last_comment
ORDER BY comment_date DESC LIMIT 1";
$last_updated_comment = $wpdb->get_results( $wpdb->prepare($last_updated_comment));
print_r( $last_updated_comment );
This produces:
Array ( [0] => stdClass Object ( [comment_date] => 2012-03-09 09:03:00 ) )
Therefore, I add the foreach statement to access the object within the array:
foreach($last_updated_comment as $key => $object){
print_r( $object);
echo "<br /><br />";
}
@Stephen Harris, Thanks for the syntax help. Next, foreach object, get the date:
foreach($object as $key => $date_lookup){
echo $date_lookup . '<br /><br />';
}
With output:
$date_lookup = 2012-03-09 09:03:00
Part 2: Comparing dates in SQL statement
Now that I've obtained the reference date, I want to get all comments from wp_comments after $date_lookup:
global $wpdb;
$sql = "
SELECT comment_post_ID, comment_author, comment_author_email, comment_date, comment_content, comment_approved, comment_type, comment_parent
FROM wp_comments WHERE comment_date > '%$date_lookup%' ";
$new_comments = $wpdb->get_results($sql);
print_r( $new_comments );
Now it seems that the > operator is looking at the time and ignoring the year because my output includes an array of comments with dates from 2011.
Is the > operator the correct tool to use?