wppaste
WordPress

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

Since
4.9.8
Source
wp-includes/meta.php:1794
Returns the object subtype for a given object ID of a specific type.

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

Reaches the database via get_term().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
13–28

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 53.

Plugin surface
1 hook

Third-party callbacks on 'get_object_subtype_{$object_type}' run inside this call, and their cost is not bounded by anything here.

Called by
8

8 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_term()called directly
  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
always13–22apply_filters()
always18–26get_comment(), apply_filters()
always19–23get_post_type(), apply_filters()
always19–26get_term(), apply_filters()
always19–28get_user_by(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev5313–289
8.55313–289
8.45313–289
8.35313–289
8.25313–2891 more instruction than PHP 8.1
8.15213–299
7.45213–299

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:

  1. apply_filters( get_object_subtype_{$object_type} )filterline 1854 (+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

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 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.