It depends on the context of the current post. If it’s a single post query, the comments are already in the WP_Query object. By default they’re sorted by date, so unless that’s been changed, just grab the first comment in the array.
If it’s an archive type list, there are no comments in the query, you need to query for the comments yourself. You can use WP_Comment_Query and limit the query to 1 result, but for max efficiency, create your own SQL query and execute it with the global $wpdb object.
No matter how you get the comment object, the time fields are datetime strings, so you need to convert to a timestamp with strtotime().
(@robin_dean)
9 years, 5 months ago
Hi all.
For the current post, I need to know the Unix (‘U’) timestamp for the most recent comment on the very same post. I’m comparing that against filemtime on another file.
What’s the quickest, “least expensive” way to grab said data?