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
if ( !function_exists( 'get_post_type' ) ) { require_once ABSPATH . WPINC . '/post.php'; } // Optional. Post ID or post object. Default is global $post. $post = null; // NOTICE! Understand what this does before running. $result = get_post_type($post);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/post.php
- function get_post_type( $post = null ) {
- if ( $post = get_post( $post ) )
- return $post->post_type;
- return false;
- }