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

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

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

Source file: wp-includes/post.php

View source


Parameters

$post

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

Default value: null


Used by


Source

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

	return false;
}


Changelog


User Contributed Notes

  1. Display the post type. This example needs to be inside the loop.

    printf( __( 'The post type is: %s', 'textdomain' ), get_post_type( get_the_ID() ) );
    

You must log in before being able to contribute a note.