get_post_type_labels( object|WP_Post_Type $post_type_object ): object
- Since
- 3.0.0, 4.3.0, 4.4.0, 4.6.0, 4.7.0, 5.0.0, 5.7.0, 5.8.0, 6.3.0, 6.4.0, 6.6.0, 6.7.0
- Source
wp-includes/post.php:2139
Description
Accepted keys of the label array in the post type object:
name- General name for the post type, usually plural. The same and overridden by$post_type_object->label. Default is 'Posts' / 'Pages'.singular_name- Name for one object of this post type. Default is 'Post' / 'Page'.add_new- Label for adding a new item. Default is 'Add Post' / 'Add Page'.add_new_item- Label for adding a new singular item. Default is 'Add Post' / 'Add Page'.edit_item- Label for editing a singular item. Default is 'Edit Post' / 'Edit Page'.new_item- Label for the new item page title. Default is 'New Post' / 'New Page'.view_item- Label for viewing a singular item. Default is 'View Post' / 'View Page'.view_items- Label for viewing post type archives. Default is 'View Posts' / 'View Pages'.search_items- Label for searching plural items. Default is 'Search Posts' / 'Search Pages'.not_found- Label used when no items are found. Default is 'No posts found' / 'No pages found'.not_found_in_trash- Label used when no items are in the Trash. Default is 'No posts found in Trash' / 'No pages found in Trash'.parent_item_colon- Label used to prefix parents of hierarchical items. Not used on non-hierarchical post types. Default is 'Parent Page:'.all_items- Label to signify all items in a submenu link. Default is 'All Posts' / 'All Pages'.archives- Label for archives in nav menus. Default is 'Post Archives' / 'Page Archives'.attributes- Label for the attributes meta box. Default is 'Post Attributes' / 'Page Attributes'.insert_into_item- Label for the media frame button. Default is 'Insert into post' / 'Insert into page'.uploaded_to_this_item- Label for the media frame filter. Default is 'Uploaded to this post' / 'Uploaded to this page'.featured_image- Label for the featured image meta box title. Default is 'Featured image'.set_featured_image- Label for setting the featured image. Default is 'Set featured image'.remove_featured_image- Label for removing the featured image. Default is 'Remove featured image'.use_featured_image- Label in the media frame for using a featured image. Default is 'Use as featured image'.menu_name- Label for the menu name. Default is the same asname.filter_items_list- Label for the table views hidden heading. Default is 'Filter posts list' / 'Filter pages list'.filter_by_date- Label for the date filter in list tables. Default is 'Filter by date'.items_list_navigation- Label for the table pagination hidden heading. Default is 'Posts list navigation' / 'Pages list navigation'.items_list- Label for the table hidden heading. Default is 'Posts list' / 'Pages list'.item_published- Label used when an item is published. Default is 'Post published.' / 'Page published.'item_published_privately- Label used when an item is published with private visibility.
Default is 'Post published privately.' / 'Page published privately.'item_reverted_to_draft- Label used when an item is switched to a draft.
Default is 'Post reverted to draft.' / 'Page reverted to draft.'item_trashed- Label used when an item is moved to Trash. Default is 'Post trashed.' / 'Page trashed.'item_scheduled- Label used when an item is scheduled for publishing. Default is 'Post scheduled.' / 'Page scheduled.'item_updated- Label used when an item is updated. Default is 'Post updated.' / 'Page updated.'item_link- Title for a navigation link block variation. Default is 'Post Link' / 'Page Link'.item_link_description- Description for a navigation link block variation. Default is 'A link to a post.' / 'A link to a page.'
Above, the first default value is for non-hierarchical post types (like posts) and the second one is for hierarchical post types (like pages).
Note: To set labels used in post type admin notices, see the 'post_updated_messages' filter.
Compatibility
- WordPress
- since 6.7.0
- 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
$post_type_objectobject|WP_Post_Type- Post type object.
Return value
object- Object with all the labels as member variables.
Performance profile
How much work a call to get_post_type_labels() 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
- Trivial
- Scaling
- Constant
- Instructions
- 32–46
- Plugin surface
- 1 hook
- Called by
- 1
Touches nothing outside its own arguments.
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 46.
Third-party callbacks on 'post_type_labels_{$post_type}' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach query, 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 · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_post_type_labels() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 32–35 | ::WP_Post_Type(), _get_custom_object_labels(), apply_filters(), array_merge() |
| always | 46 | ::WP_Post_Type(), _get_custom_object_labels(), __(), sprintf(), apply_filters(), array_merge() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 46 instructions, 32–46 executed per call, 2 branches. The work does not change between versions.
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_post_type_labels() runs, in this order:
- apply_filters( post_type_labels_{$post_type} )filterline 2173 (+34 into the body)
Filters the labels of a specific post type.
Uses · 4
- _get_custom_object_labels()Builds an object with custom-something object (post type, taxonomy) labels out of a custom-something object
- __()Retrieves the translation of $text.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Post_Type::get_default_labels()Returns the default labels for post types.
Used by · 1
- WP_Post_Type::set_props()Sets post type properties.
Source code
function get_post_type_labels( $post_type_object ) { $nohier_vs_hier_defaults = WP_Post_Type::get_default_labels(); $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; $labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults ); if ( ! isset( $post_type_object->labels->template_name ) && isset( $post_type_object->labels->singular_name ) ) { /* translators: %s: Post type name. */ $labels->template_name = sprintf( __( 'Single item: %s' ), $post_type_object->labels->singular_name ); } $post_type = $post_type_object->name; $default_labels = clone $labels; /** * Filters the labels of a specific post type. * * The dynamic portion of the hook name, `$post_type`, refers to * the post type slug. * * Possible hook names include: * * - `post_type_labels_post` * - `post_type_labels_page` * - `post_type_labels_attachment` * * @since 3.5.0 * * @see get_post_type_labels() for the full list of labels. * * @param object $labels Object with labels for the post type as member variables. */ $labels = apply_filters( "post_type_labels_{$post_type}", $labels ); // Ensure that the filtered labels contain all required default values. $labels = (object) array_merge( (array) $default_labels, (array) $labels ); return $labels;}Changelog
Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
add_new label and updated documentation.Updated core usage to reference
add_new_item.from the docblocktemplate_name label.from the docblockadd_new label to include the type of content.This matches
add_new_item and provides more context for better accessibility.from the docblockitem_trashed label.from the docblockitem_link and item_link_description labels.from the docblockfilter_by_date label.from the docblockitem_published, item_published_privately, item_reverted_to_draft, item_scheduled, and item_updated labels.from the docblockview_items and attributes labels.from the docblock$post_type parameter to accept a WP_Post_Type object.from the docblockarchives, insert_into_item, uploaded_to_this_item, filter_items_list, items_list_navigation, and items_list labels.from the docblockfeatured_image, set_featured_image, remove_featured_image, and use_featured_image labels.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/post.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.