get_lastpostdate( string $timezone = 'server', string $post_type = 'any' ): string

In this article

Retrieves the most recent time that a post on the site was published.

Description

The server timezone is the default and is the difference between GMT and server time. The ‘blog’ value is the date when the last post was posted.
The ‘gmt’ is when the last post was posted in GMT formatted date.

Parameters

$timezonestringoptional
The timezone for the timestamp. Accepts 'server', 'blog', or 'gmt'.
'server' uses the server’s internal timezone.
'blog' uses the post_date field, which proxies to the timezone set for the site.
'gmt' uses the post_date_gmt field.
Default 'server'.

Default:'server'

$post_typestringoptional
The post type to check. Default 'any'.

Default:'any'

Return

string The date of the last post, or false on failure.

Source


// Only need to check the cap if $public_only is false.
$post_status_sql = "post_status = 'publish'";

if ( false === $public_only ) {
	if ( $cap ) {
		// Does the user have the capability to view private posts? Guess so.
		$post_status_sql .= " OR post_status = 'private'";
	} elseif ( is_user_logged_in() ) {
		// Users can view their own private posts.
		$id = get_current_user_id();
		if ( null === $post_author || ! $full ) {
			$post_status_sql .= " OR post_status = 'private' AND post_author = $id";
		} elseif ( $id === (int) $post_author ) {
			$post_status_sql .= " OR post_status = 'private'";
		} // Else none.
	} // Else none.

Changelog

VersionDescription
4.4.0The $post_type argument was added.
0.71Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.