get_object_subtype

The timeline below displays how wordpress function get_object_subtype has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.9

/**
 * Returns the object subtype for a given object ID of a specific type.
 *
 * @since 4.9.8
 *
 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                            or any other object type with an associated meta table.
 * @param int    $object_id   ID of the object to retrieve its subtype.
 * @return string The object subtype or an empty string if unspecified subtype.
 */
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 name, `$object_type`, refers to the meta object type
     * (post, comment, term, user, or any other type with an associated meta table).
     *
     * Possible hook names include:
     *
     *  - `get_object_subtype_post`
     *  - `get_object_subtype_comment`
     *  - `get_object_subtype_term`
     *  - `get_object_subtype_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);
}

WordPress Version: 5.5

/**
 * Returns the object subtype for a given object ID of a specific type.
 *
 * @since 4.9.8
 *
 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                            or any other object type with an associated meta table.
 * @param int    $object_id   ID of the object to retrieve its subtype.
 * @return string The object subtype or an empty string if unspecified subtype.
 */
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 meta object type
     * (post, comment, term, user, or any other type with an associated meta table).
     *
     * @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);
}

WordPress Version: 5.4

/**
 * Returns the object subtype for a given object ID of a specific type.
 *
 * @since 4.9.8
 *
 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                            or any other object type with an associated meta table.
 * @param int    $object_id   ID of the object to retrieve its subtype.
 * @return string The object subtype or an empty string if unspecified subtype.
 */
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);
}

WordPress Version: .10

/**
 * Returns the object subtype for a given object ID of a specific type.
 *
 * @since 4.9.8
 *
 * @param string $object_type Type of object to request metadata for. (e.g. comment, post, term, user)
 * @param int    $object_id   ID of the object to retrieve its subtype.
 * @return string The object subtype or an empty string if unspecified subtype.
 */
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);
}