On this page
get_post_type( int|WP_Post|null $post = null ): string|false
Retrieves the post type of the current post or of a given post.
Parameters
$postint|WP_Post|null Optional-
Post ID or post object. Default is global $post.
Default:
null
Return
string|false Post type on success, false on failure.
Source
File: wp-includes/post.php. View all references
function get_post_type( $post = null ) {
$post = get_post( $post );
if ( $post ) {
return $post->post_type;
}
return false;
}
Related
Uses
| Uses | Description |
|---|---|
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Menu_Items_Controller::prepare_links() wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares links for the request. |
| WP_REST_Menu_Items_Controller::prepare_item_for_database() wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post for create or update. |
| _disable_content_editor_for_navigation_post_type() wp-admin/includes/post.php | This callback disables the content editor for wp_navigation type posts. |
| _enable_content_editor_for_navigation_post_type() wp-admin/includes/post.php | This callback enables content editor for wp_navigation type posts. |
| wp_force_plain_post_permalink() wp-includes/link-template.php | Determine whether post should always use a plain permalink structure. |
| is_post_publicly_viewable() wp-includes/post.php | Determines whether a post is publicly viewable. |
| WP_Customize_Manager::preserve_insert_changeset_post_content() wp-includes/class-wp-customize-manager.php | Preserves the initial JSON post_content passed to save into the post. |
| get_object_subtype() wp-includes/meta.php | Returns the object subtype for a given object ID of a specific type. |
| wp_check_for_changed_dates() wp-includes/post.php | Checks for changed dates for published post objects and save the old date. |
| WP_Customize_Manager::grant_edit_post_capability_for_changeset() wp-includes/class-wp-customize-manager.php | Re-maps ‘edit_post’ meta cap for a customize_changeset post to be the same as ‘customize’ maps. |
| WP_Embed::find_oembed_post_id() wp-includes/class-wp-embed.php | Finds the oEmbed cache post ID for a given cache key. |
| WP_Widget_Media_Gallery::has_content() wp-includes/widgets/class-wp-widget-media-gallery.php | Whether the widget has content to show. |
| WP_Widget_Media::has_content() wp-includes/widgets/class-wp-widget-media.php | Whether the widget has content to show. |
| WP_Customize_Manager::has_published_pages() wp-includes/class-wp-customize-manager.php | Returns whether there are published pages. |
| WP_Customize_Manager::find_changeset_post_id() wp-includes/class-wp-customize-manager.php | Finds the changeset post ID for a given changeset UUID. |
| WP_Customize_Manager::get_changeset_post_data() wp-includes/class-wp-customize-manager.php | Gets the data stored in a changeset post. |
| WP_REST_Attachments_Controller::create_item() wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php | Creates a single attachment. |
| WP_REST_Attachments_Controller::update_item() wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php | Updates a single attachment. |
| WP_REST_Posts_Controller::prepare_item_for_database() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares a single post for create or update. |
| WP_Customize_Nav_Menus::save_nav_menus_created_posts() wp-includes/class-wp-customize-nav-menus.php | Publishes the auto-draft posts that were created for nav menu items. |
| get_oembed_response_data_rich() wp-includes/embed.php | Filters the oEmbed response data to return an iframe embed code. |
| _update_posts_count_on_transition_post_status() wp-includes/ms-blogs.php | Handler for updating the current site’s posts count when a post status changes. |
| get_media_item() wp-admin/includes/media.php | Retrieves HTML form for modifying the image attachment. |
| bulk_edit_posts() wp-admin/includes/post.php | Processes the post data for the bulk editing of posts. |
| _wp_ajax_menu_quick_search() wp-admin/includes/nav-menu.php | Prints the appropriate response to a menu quick search. |
| get_the_category_list() wp-includes/category-template.php | Retrieves category list for a post in either HTML list or custom format. |
| WP_Theme::get_page_templates() wp-includes/class-wp-theme.php | Returns the theme’s post templates for a given post type. |
| get_attachment_link() wp-includes/link-template.php | Retrieves the permalink for an attachment. |
| wp_check_for_changed_slugs() wp-includes/post.php | Checks for changed slugs for published post objects and save the old slug. |
| wp_set_post_categories() wp-includes/post.php | Sets categories for a post. |
| is_nav_menu_item() wp-includes/nav-menu.php | Determines whether the given ID is a nav menu item. |
| wp_xmlrpc_server::_insert_post() wp-includes/class-wp-xmlrpc-server.php | Helper method for wp_newPost() and wp_editPost(), containing shared logic. |
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_post_type