get_object_subtype( string $object_type, int $object_id ): string
- Since
- 4.9.8
- Source
wp-includes/meta.php:1798
Compatibility
- WordPress
- since 4.9.8
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$object_typestring- Type of object metadata is for. Accepts 'blog', 'post', 'comment', 'term', 'user', or any other object type with an associated meta table.
$object_idint- ID of the object to retrieve its subtype.
Return value
string- The object subtype or an empty string if unspecified subtype.
Performance profile
How much work a call to get_object_subtype() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 13–28
- Plugin surface
- 1 hook
- Called by
- 8
Reaches the database via get_term().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 53.
Third-party callbacks on 'get_object_subtype_{$object_type}' run inside this call, and their cost is not bounded by anything here.
8 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_term()called directly - hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_object_subtype() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 13–22 | apply_filters() |
| always | 18–26 | get_comment(), apply_filters() |
| always | 19–23 | get_post_type(), apply_filters() |
| always | 19–26 | get_term(), apply_filters() |
| always | 19–28 | get_user_by(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 53 | 13–28 | 9 | |
| 8.5 | 53 | 13–28 | 9 | |
| 8.4 | 53 | 13–28 | 9 | |
| 8.3 | 53 | 13–28 | 9 | |
| 8.2 | 53 | 13–28 | 9 | 1 more instruction than PHP 8.1 |
| 8.1 | 52 | 13–29 | 9 | |
| 7.4 | 52 | 13–29 | 9 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while get_object_subtype() runs, in this order:
- apply_filters( get_object_subtype_{$object_type} )filterline 1858 (+60 into the body)
Filters the object subtype identifier.
Uses · 5
- get_post_type()Retrieves the post type of the current post or of a given post.
- get_term()Gets all term data from database by term ID.
- get_comment()Retrieves comment data given a comment ID or comment object.
- get_user_by()Retrieves user info by a given field.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 8
- WP_REST_Meta_Fields::update_meta_value()Updates a meta value for an object.
- WP_REST_Meta_Fields::update_multi_meta_value()Updates multiple meta values for an object.
- add_metadata()Adds metadata for the specified object.
- filter_default_metadata()Filters into default_{$object_type}_metadata and adds in default value.
- get_registered_metadata()Retrieves registered metadata for a specified object.
- map_meta_cap()Maps a capability to the primitive capabilities required of the given user to satisfy the capability being checked.
- update_metadata()Updates metadata for the specified object. If no value already exists for the specified object ID and metadata key, the metadata will be added.
- update_metadata_by_mid()Updates metadata by meta ID.
Source code
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 );}Changelog
Introduced in 4.9.8. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/meta.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.