wordpress / latest / functions / get_post_type.html

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

$post int|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;
}

Uses

Uses Description

Used By

Used By Description

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