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:
get_lastpostdate($timezone='server', $postType='any')
Set the $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:
get_lastpostmodified($timezone='server', $postType='any')
Parameters are the same as get_lastpostdate
function.
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:
How to get WordPress Post Date using PHP?
How to set publishing date and time for a WordPress post Programmatically?
written by Mehdi Nazari about in WordPress WordPress Functions WordPress Plugin Development WordPress Theme Development
What do you think about "How to get Publish Date of The Last Post in WordPress"?