WPSEO_Meta::post_types_for_ids()public staticYoast 1.0

Returns the post types for the given post ids.

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

Хуков нет.

Возвращает

Массив. The post types.

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

$result = WPSEO_Meta::post_types_for_ids( $post_ids );
$post_ids(массив) (обязательный)
The post ids to get the post types for.

Код WPSEO_Meta::post_types_for_ids() Yoast 24.9

public static function post_types_for_ids( $post_ids ) {

	/**
	 * The indexable repository.
	 *
	 * @var Indexable_Repository $repository
	 */
	$repository = YoastSEO()->classes->get( Indexable_Repository::class );

	// Check if post ids is not empty.
	if ( ! empty( $post_ids ) ) {
		// Get the post subtypes for the posts that share the keyword.
		$post_types = $repository->query()
			->select( 'object_sub_type' )
			->where_in( 'object_id', $post_ids )
			->find_array();

		// Get object_sub_type from each subarray in $post_ids.
		$post_types = array_column( $post_types, 'object_sub_type' );
	}
	else {
		$post_types = [];
	}

	return $post_types;
}