# _get_last_post_time()

URL: https://chugunov.pro/api-wordpress/functions/_get_last_post_time/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 3.1.0.

## Сигнатура

```php
_get_last_post_time( string $timezone, string $field, string $post_type = 'any' ): string|false
```

## Описание

Получает метку времени последнего изменения или публикации любой записи.

## Параметры

- `$timezone` `string` — обязательный. Часовой пояс для метки времени. См. get_lastpostdate() .
  
  для сведений о допустимых значениях.
- `$field` `string` — обязательный. Поле записи для проверки. Принимает 'date' или 'modified'.
- `$post_type` `string` — необязательный, по умолчанию `'any'`. Тип записи для проверки. Значение по умолчанию 'any'.

## Возвращаемое значение

`string|false`

## Исходный код

Файл: `wp-includes/post.php:7632`

```php
function _get_last_post_time( $timezone, $field, $post_type = 'any' ) {
	global $wpdb;

	if ( ! in_array( $field, array( 'date', 'modified' ), true ) ) {
		return false;
	}

	$timezone = strtolower( $timezone );

	$key = "lastpost{$field}:$timezone";
	if ( 'any' !== $post_type ) {
		$key .= ':' . sanitize_key( $post_type );
	}

	$date = wp_cache_get( $key, 'timeinfo' );
	if ( false !== $date ) {
		return $date;
	}

	if ( 'any' === $post_type ) {
		$post_types = get_post_types( array( 'public' => true ) );
		array_walk( $post_types, array( $wpdb, 'escape_by_ref' ) );
		$post_types = "'" . implode( "', '", $post_types ) . "'";
	} else {
		$post_types = "'" . sanitize_key( $post_type ) . "'";
	}

	switch ( $timezone ) {
		case 'gmt':
			$date = $wpdb->get_var( "SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" );
			break;
		case 'blog':
			$date = $wpdb->get_var( "SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" );
			break;
		case 'server':
			$add_seconds_server = gmdate( 'Z' );
			$date               = $wpdb->get_var( "SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" );
			break;
	}

	if ( $date ) {
		wp_cache_set( $key, $date, 'timeinfo' );

		return $date;
	}

	return false;
}
```

## История изменений

- 4.4.0 — The $post_type argument was added.
- 3.1.0 — Introduced.

## Связанные

Использует: [`wp_cache_set`](https://chugunov.pro/api-wordpress/functions/wp_cache_set/), [`wp_cache_get`](https://chugunov.pro/api-wordpress/functions/wp_cache_get/), [`sanitize_key`](https://chugunov.pro/api-wordpress/functions/sanitize_key/), [`get_post_types`](https://chugunov.pro/api-wordpress/functions/get_post_types/), `wpdb::get_var`.
Используется в: [`get_lastpostdate`](https://chugunov.pro/api-wordpress/functions/get_lastpostdate/), [`get_lastpostmodified`](https://chugunov.pro/api-wordpress/functions/get_lastpostmodified/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/_get_last_post_time/
