WordPress at Your Fingertips

get_post_type() WP 1.0

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

Uses: get_post()
1 time — 0.000637 sec (slow) | 50000 times — 0.17 sec (very fast) | PHP 7.1.2, WP 4.7.5

No Hooks.

Return

String|false. Post type on success, false on failure.

Usage

get_post_type( $post );
$post(int|WP_Post|null)
Post ID or post object.
Default: global $post

Changelog

Since 2.1.0 Introduced.

Code of get_post_type() WP 5.8

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

	return false;
}

From tag: Custom post type (post_type)

More from category: Custom Types

No comments
    Log In