get_post_type

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

Description

(string|false) get_post_type( (null) $post = null ); 

Returns (string|false)

Post type on success, false on failure.

Parameters (1)

0. $post — Optional. (null) => null
Post ID or post object. Default is global $post.

Usage

  1. if ( !function_exists( 'get_post_type' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Optional. Post ID or post object. Default is global $post. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_post_type($post); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function get_post_type( $post = null ) { 
  2. if ( $post = get_post( $post ) ) 
  3. return $post->post_type; 
  4.  
  5. return false;