返回特定类型的给定对象ID的对象子类型。

原型

get_object_subtype( string $object_type, int $object_id )

参数

$object_type (string) (Required) 要为其请求元数据的对象类型。 (例如评论,帖子,期限,用户)

$object_id (int) (Required) 要检索其子类型的对象的ID。

返回值

(string)  对象子类型,如果未指定子类型,则为空字符串。

源文件

路径:wp-includes/meta.php

<?php
...
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 for a non standard object type.
	 *
	 * The dynamic portion of the hook, `$object_type`, refers to the object
	 * type (post, comment, term, or user).
	 *
	 * @since 4.9.8
	 *
	 * @param string $object_subtype 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 );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/get_object_subtype/