WPSEO_Post_Type_Sitemap_Provider::get_all_dates_using_with_clause
Get all dates for a post type by using the WITH clause for performance.
Метод класса: WPSEO_Post_Type_Sitemap_Provider{}
Хуков нет.
Возвращает
Массив. Array of dates.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_all_dates_using_with_clause( $post_type, $max_entries );
- $post_type(строка) (обязательный)
- Post type to retrieve dates for.
- $max_entries(int) (обязательный)
- Maximum number of entries to retrieve.
Код WPSEO_Post_Type_Sitemap_Provider::get_all_dates_using_with_clause() WPSEO Post Type Sitemap Provider::get all dates using with clause Yoast 27.4
private function get_all_dates_using_with_clause( $post_type, $max_entries ) {
global $wpdb;
$post_statuses = array_map( 'esc_sql', WPSEO_Sitemaps::get_post_statuses( $post_type ) );
$replacements = array_merge(
[
'ordering',
'post_modified_gmt',
$wpdb->posts,
'type_status_date',
'post_status',
],
$post_statuses,
[
'post_type',
$post_type,
'post_modified_gmt',
'post_modified_gmt',
'ordering',
$max_entries,
],
);
//phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- We need to use a direct query here.
//phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
return $wpdb->get_col(
//phpcs:disable WordPress.DB.PreparedSQLPlaceholders -- %i placeholder is still not recognized.
$wpdb->prepare(
'
WITH %i AS (SELECT ROW_NUMBER() OVER (ORDER BY %i) AS n, post_modified_gmt
FROM %i USE INDEX ( %i )
WHERE %i IN (' . implode( ', ', array_fill( 0, count( $post_statuses ), '%s' ) ) . ')
AND %i = %s
ORDER BY %i)
SELECT %i
FROM %i
WHERE MOD(n, %d) = 0;
',
$replacements,
),
);
}