On this page
get_object_subtype( string $object_type, int $object_id ): string
Returns the object subtype for a given object ID of a specific type.
Parameters
$object_typestring Required-
Type of object metadata is for. Accepts
'post','comment','term','user', or any other object type with an associated meta table. $object_idint Required-
ID of the object to retrieve its subtype.
Return
string The object subtype or an empty string if unspecified subtype.
Source
File: wp-includes/meta.php. View all references
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 );
}
Hooks
- apply_filters( "get_object_subtype_{$object_type}",
string $object_subtype ,int $object_id ) -
Filters the object subtype identifier for a non-standard object type.
Related
Uses
| Uses | Description |
|---|---|
| get_user_by() wp-includes/pluggable.php | Retrieves user info by a given field. |
| get_post_type() wp-includes/post.php | Retrieves the post type of the current post or of a given post. |
| get_term() wp-includes/taxonomy.php | Gets all term data from database by term ID. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_comment() wp-includes/comment.php | Retrieves comment data given a comment ID or comment object. |
Used By
| Used By | Description |
|---|---|
| filter_default_metadata() wp-includes/meta.php | Filters into default_{$object_type}_metadata and adds in default value. |
| WP_REST_Meta_Fields::update_multi_meta_value() wp-includes/rest-api/fields/class-wp-rest-meta-fields.php | Updates multiple meta values for an object. |
| WP_REST_Meta_Fields::update_meta_value() wp-includes/rest-api/fields/class-wp-rest-meta-fields.php | Updates a meta value for an object. |
| get_registered_metadata() wp-includes/meta.php | Retrieves registered metadata for a specified object. |
| map_meta_cap() wp-includes/capabilities.php | Maps a capability to the primitive capabilities required of the given user to satisfy the capability being checked. |
| update_metadata_by_mid() wp-includes/meta.php | Updates metadata by meta ID. |
| add_metadata() wp-includes/meta.php | Adds metadata for the specified object. |
| update_metadata() wp-includes/meta.php | Updates metadata for the specified object. If no value already exists for the specified object ID and metadata key, the metadata will be added. |
Changelog
| Version | Description |
|---|---|
| 4.9.8 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_object_subtype