get_post_type() WordPress Function

The get_post_type() function is used to get the post type of the current post.

get_post_type( int|WP_Post|null $post = null ) #

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


Parameters

$post

(int|WP_Post|null)(Optional) Post ID or post object. Default is global $post.

Default value: null


Top ↑

Return

(string|false) Post type on success, false on failure.


Top ↑

Source

File: wp-includes/post.php

function get_post_type( $post = null ) {
	$post = get_post( $post );
	if ( $post ) {
		return $post->post_type;
	}

	return false;
}


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More