WordPress has two perfect functions to get Publish Date of the Last Post. get_lastpostdate and get_lastpostmodified functions are helpful when the developer wants to retrieve Latest Post's Dates. In this WordPress tutorial for beginners, We will try these two functions in a working environment and check if they return what we want?
How to get Last Post Publish Date using the
get_lastpostdate function in WordPress?
get_lastpostdate function is helpful when you want to retrieve the latest post publish date.
This function’s syntax is easy to understand:
$timezone parameter to get the date based on your selected timezone.
$postType can determine what type of posts you want information about.
How to get the Date that a Post was Modified using the
get_lastpostmodified function in WordPress?
get_lastpostmodified function will return a date string that represents the last date and time a post was modified on the current website.
The syntax is much like the previous function:
Parameters are the same as
Example of running these two functions in my case:
$lastPostPublishDate = get_lastpostdate(); //value: 2021-11-03 07:32:44.000000 $lastPostModifyDate = get_lastpostmodified(); //value: 2021-11-05 11:30:53.000000
Returned value was correct for me in the local work space.
If you are interested in more information about post dates, you can follow these articles on my blog:
What do you think about "How to get Publish Date of The Last Post in WordPress"?