Yoast\WP\SEO\Builders

Indexable_Term_Builder::get_object_timestamps()protectedYoast 1.0

Returns the timestamps for a given term.

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

Хуков нет.

Возвращает

Объект. An object with last_modified and published_at timestamps.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_object_timestamps( $term_id, $taxonomy );
$term_id(int) (обязательный)
The term ID.
$taxonomy(строка) (обязательный)
The taxonomy.

Код Indexable_Term_Builder::get_object_timestamps() Yoast 22.1

protected function get_object_timestamps( $term_id, $taxonomy ) {
	global $wpdb;
	$post_statuses = $this->post_helper->get_public_post_statuses();

	$replacements   = [];
	$replacements[] = 'post_modified_gmt';
	$replacements[] = 'post_date_gmt';
	$replacements[] = $wpdb->posts;
	$replacements[] = $wpdb->term_relationships;
	$replacements[] = 'object_id';
	$replacements[] = 'ID';
	$replacements[] = $wpdb->term_taxonomy;
	$replacements[] = 'term_taxonomy_id';
	$replacements[] = 'term_taxonomy_id';
	$replacements[] = 'taxonomy';
	$replacements[] = $taxonomy;
	$replacements[] = 'term_id';
	$replacements[] = $term_id;
	$replacements[] = 'post_status';
	$replacements   = \array_merge( $replacements, $post_statuses );
	$replacements[] = 'post_password';

	//phpcs:disable WordPress.DB.PreparedSQLPlaceholders -- %i placeholder is still not recognized.
	//phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
	//phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
	return $wpdb->get_row(
		$wpdb->prepare(
			'
		SELECT MAX(p.%i) AS last_modified, MIN(p.%i) AS published_at
		FROM %i AS p
		INNER JOIN %i AS term_rel
			ON		term_rel.%i = p.%i
		INNER JOIN %i AS term_tax
			ON		term_tax.%i = term_rel.%i
			AND		term_tax.%i = %s
			AND		term_tax.%i = %d
		WHERE	p.%i IN (' . \implode( ', ', \array_fill( 0, \count( $post_statuses ), '%s' ) ) . ")
			AND		p.%i = ''
		",
			$replacements
		)
	);
	//phpcs:enable
}