функция since 4.9.8

get_object_subtype()

Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.

Сигнатура

get_object_subtype( string $object_type, int $object_id ): string

Описание

Возвращает подтип объекта для указанного идентификатора объекта определённого типа.

Параметры

$object_type string обязательный
Тип объекта, к которому относятся метаданные. Принимает 'blog', 'post', 'comment', 'term', 'user' или любой другой тип объекта со связанной таблицей метаданных.
$object_id int обязательный
Идентификатор объекта, подтип которого нужно получить.

Возвращаемое значение

string

Исходный код

wp-includes/meta.php:1798

function get_object_subtype( $object_type, $object_id ) {
	$object_id      = (int) $object_id;
	$object_subtype = '';

	switch ( $object_type ) {
		case 'post':
			$post_type = get_post_type( $object_id );

			if ( ! empty( $post_type ) ) {
				$object_subtype = $post_type;
			}
			break;

		case 'term':
			$term = get_term( $object_id );
			if ( ! $term instanceof WP_Term ) {
				break;
			}

			$object_subtype = $term->taxonomy;
			break;

		case 'comment':
			$comment = get_comment( $object_id );
			if ( ! $comment ) {
				break;
			}

			$object_subtype = 'comment';
			break;

		case 'user':
			$user = get_user_by( 'id', $object_id );
			if ( ! $user ) {
				break;
			}

			$object_subtype = 'user';
			break;
	}

	/**
	 * Filters the object subtype identifier.
	 *
	 * The dynamic portion of the hook name, `$object_type`, refers to the meta object type
	 * (blog, post, comment, term, user, or any other type with an associated meta table).
	 *
	 * Possible hook names include:
	 *
	 *  - `get_object_subtype_blog`
	 *  - `get_object_subtype_post`
	 *  - `get_object_subtype_comment`
	 *  - `get_object_subtype_term`
	 *  - `get_object_subtype_user`
	 *
	 * @since 4.9.8
	 *
	 * @param string $object_subtype Object subtype or empty string to override.
	 * @param int    $object_id      ID of the object to get the subtype for.
	 */
	return apply_filters( "get_object_subtype_{$object_type}", $object_subtype, $object_id );
}

История изменений

ВерсияОписание
4.9.8 Introduced.

Что будем искать? Например,Продвижение

Этот сайт использует куки-файлы. Оставаясь на сайте, Вы соглашаетесь на их использование. Для получения дополнительной информации, пожалуйста, ознакомьтесь с политикой в отношении персональных данных.