WPSEO_Sitemaps::get_last_modified_gmt()
Get the GMT modification date for the last modified post in the post type.
Метод класса: WPSEO_Sitemaps{}
Хуков нет.
Возвращает
Строку|Массив|false
.
Использование
$result = WPSEO_Sitemaps::get_last_modified_gmt( $post_types, $return_all );
- $post_types(строка|массив) (обязательный)
- Post type or array of types.
- $return_all(true|false)
- Flag to return array of values.
По умолчанию: false
Список изменений
С версии 3.2 | Введена. |
Код WPSEO_Sitemaps::get_last_modified_gmt() WPSEO Sitemaps::get last modified gmt Yoast 20.0
public static function get_last_modified_gmt( $post_types, $return_all = false ) { global $wpdb; static $post_type_dates = null; if ( ! is_array( $post_types ) ) { $post_types = [ $post_types ]; } foreach ( $post_types as $post_type ) { if ( ! isset( $post_type_dates[ $post_type ] ) ) { // If we hadn't seen post type before. R. $post_type_dates = null; break; } } if ( is_null( $post_type_dates ) ) { $post_type_dates = []; $post_type_names = WPSEO_Post_Type::get_accessible_post_types(); if ( ! empty( $post_type_names ) ) { $post_statuses = array_map( 'esc_sql', self::get_post_statuses() ); $sql = " SELECT post_type, MAX(post_modified_gmt) AS date FROM $wpdb->posts WHERE post_status IN ('" . implode( "','", $post_statuses ) . "') AND post_type IN ('" . implode( "','", $post_type_names ) . "') GROUP BY post_type ORDER BY date DESC "; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery -- They are prepared on the lines above and a direct query is required. foreach ( $wpdb->get_results( $sql ) as $obj ) { $post_type_dates[ $obj->post_type ] = $obj->date; } } } $dates = array_intersect_key( $post_type_dates, array_flip( $post_types ) ); if ( count( $dates ) > 0 ) { if ( $return_all ) { return $dates; } return max( $dates ); } return false; }