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

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

Description Description

Parameters Parameters


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

Default value: null

Top ↑

Return Return

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

Top ↑

Source Source

File: wp-includes/post.php

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

	return false;

Top ↑

Changelog Changelog

Version Description
2.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    Contributed by ThemesMatic

    is commonly used in conjunction with Post Formats.
    Functionality is extended in themes by including:
    add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
    in your functions.php file.

    After including this in your theme’s functions.php file, the option to choose a post type (that you included inside the array) will appear in the right sidebar when creating/editing a post.

    If no Post Type is selected, WordPress selects the default which is Standard.

    WordPress supported post formats (that are not defaults) are:
    'aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat'

    Everything you need to know about using & styling Post Formats is here:

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