WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get post type

Contents

Description

Retrieve the post type of the current post or of a given post.

Usage

<?php echo get_post_type$post ?>

Parameters

$post
(mixed) (optional) Post object or post ID. If empty, the current post will be used.
Default: null

Return Values

(boolean|string) 
post type or false on failure.

Examples

Display the post type. This example needs to be inside the loop.

<?php echo 'The post type is: ' . get_post_type( get_the_ID() ); ?>

Notes

Change Log

  • 3.5.0: The default for $post is now null instead of false, and get_post() is used instead of directly accessing the global $post variable.
  • Since: 2.1.0

Source File

get_post_type() is located in wp-includes/post.php.

Related

Post Types: register_post_type(), add_post_type_support(), remove_post_type_support(), post_type_supports(), post_type_exists(), set_post_type(), get_post_type(), get_post_types(), get_post_type_object(), get_post_type_capabilities(), get_post_type_labels(), is_post_type_hierarchical(), is_post_type_archive(), post_type_archive_title()

See also index of Function Reference and index of Template Tags.