• 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    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().

    Thread Starter robin_dean

    (@robin_dean)

    Perfect!

    Regards.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Most Recent Comment Timestamp For Current Post?’ is closed to new replies.