Replacing the_modified_date With Date of the Most Recent Comment

Sometimes theres an instance when you want to replace WordPress’ the_modified_date with the date of the most recent comment. I recently needed to do this when I was working on a small, light project tracker plugin for my department at work. In my projects archive there is a list of projects as shown below:

In this case I have comments setup as project updates, so when a team member looks at the table I wanted them to see the last time the project was updated (or a comment was posted). In the code below you will see how I replaced the date that the post itself was last modified with the date of the most recent comment while using the_modified_date as a fall back for projects that had no comments or updates.

You would replace:

With this:

this code produces this:

As you can see, the default dates do not look the same, a little bit of code on line 17 that will fix this:

Adding that code will give you this result:

 

Resources:

Leave a Reply

Your email address will not be published. Required fields are marked *