WP_Privacy_Requests_Table::get_request_counts()protectedWP 4.9.6

Counts the number of requests for each status.

Метод класса: WP_Privacy_Requests_Table{}

Хуков нет.

Возвращает

Объект. Number of posts for each status.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_request_counts();

Заметки

  • Global. wpdb. $wpdb WordPress database abstraction object.

Список изменений

С версии 4.9.6 Введена.

Код WP_Privacy_Requests_Table::get_request_counts() WP 6.5.2

protected function get_request_counts() {
	global $wpdb;

	$cache_key = $this->post_type . '-' . $this->request_type;
	$counts    = wp_cache_get( $cache_key, 'counts' );

	if ( false !== $counts ) {
		return $counts;
	}

	$query = "
		SELECT post_status, COUNT( * ) AS num_posts
		FROM {$wpdb->posts}
		WHERE post_type = %s
		AND post_name = %s
		GROUP BY post_status";

	$results = (array) $wpdb->get_results( $wpdb->prepare( $query, $this->post_type, $this->request_type ), ARRAY_A );
	$counts  = array_fill_keys( get_post_stati(), 0 );

	foreach ( $results as $row ) {
		$counts[ $row['post_status'] ] = $row['num_posts'];
	}

	$counts = (object) $counts;
	wp_cache_set( $cache_key, $counts, 'counts' );

	return $counts;
}