Title: WP_Post
Published: April 25, 2014
Last modified: May 20, 2026

---

# class WP_Post {}

## In this article

 * [More Information](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#more-information)
 * [Role of WP_Post](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#role-of-wp_post)
 * [Methods](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#wp--skip-link--target)

Core class used to implement the [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
object.

## 󠀁[More Information](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#more-information)󠁿

## 󠀁[Role of WP_Post](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#role-of-wp_post)󠁿

The [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/) class 
is used to contain post objects stored by the database and is returned by functions
such as [ get_post](https://developer.wordpress.org/reference/functions/get_post/).

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#methods)󠁿

| Name | Description | 
| [WP_Post::__construct](https://developer.wordpress.org/reference/classes/wp_post/__construct/) | Constructor. | 
| [WP_Post::__get](https://developer.wordpress.org/reference/classes/wp_post/__get/) | Getter. | 
| [WP_Post::__isset](https://developer.wordpress.org/reference/classes/wp_post/__isset/) | Isset-er. | 
| [WP_Post::filter](https://developer.wordpress.org/reference/classes/wp_post/filter/) | {@Missing Summary} | 
| [WP_Post::get_instance](https://developer.wordpress.org/reference/classes/wp_post/get_instance/) | Retrieve [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/) instance. | 
| [WP_Post::to_array](https://developer.wordpress.org/reference/classes/wp_post/to_array/) | Convert object to array. |

## 󠀁[Source](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#source)󠁿

    ```php
    #[AllowDynamicProperties]
    final class WP_Post {

    	/**
    	 * Post ID.
    	 *
    	 * @since 3.5.0
    	 * @var int
    	 */
    	public $ID;

    	/**
    	 * ID of post author.
    	 *
    	 * A numeric string, for compatibility reasons.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_author = '0';

    	/**
    	 * The post's local publication time.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_date = '0000-00-00 00:00:00';

    	/**
    	 * The post's GMT publication time.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_date_gmt = '0000-00-00 00:00:00';

    	/**
    	 * The post's content.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_content = '';

    	/**
    	 * The post's title.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_title = '';

    	/**
    	 * The post's excerpt.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_excerpt = '';

    	/**
    	 * The post's status.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_status = 'publish';

    	/**
    	 * Whether comments are allowed.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $comment_status = 'open';

    	/**
    	 * Whether pings are allowed.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $ping_status = 'open';

    	/**
    	 * The post's password in plain text.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_password = '';

    	/**
    	 * The post's slug.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_name = '';

    	/**
    	 * URLs queued to be pinged.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $to_ping = '';

    	/**
    	 * URLs that have been pinged.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $pinged = '';

    	/**
    	 * The post's local modified time.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_modified = '0000-00-00 00:00:00';

    	/**
    	 * The post's GMT modified time.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_modified_gmt = '0000-00-00 00:00:00';

    	/**
    	 * A utility DB field for post content.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_content_filtered = '';

    	/**
    	 * ID of a post's parent post.
    	 *
    	 * @since 3.5.0
    	 * @var int
    	 */
    	public $post_parent = 0;

    	/**
    	 * The unique identifier for a post, not necessarily a URL, used as the feed GUID.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $guid = '';

    	/**
    	 * A field used for ordering posts.
    	 *
    	 * @since 3.5.0
    	 * @var int
    	 */
    	public $menu_order = 0;

    	/**
    	 * The post's type, like post or page.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_type = 'post';

    	/**
    	 * An attachment's mime type.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $post_mime_type = '';

    	/**
    	 * Cached comment count.
    	 *
    	 * A numeric string, for compatibility reasons.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $comment_count = '0';

    	/**
    	 * Stores the post object's sanitization level.
    	 *
    	 * Does not correspond to a DB field.
    	 *
    	 * @since 3.5.0
    	 * @var string
    	 */
    	public $filter;

    	/**
    	 * Retrieve WP_Post instance.
    	 *
    	 * @since 3.5.0
    	 *
    	 * @global wpdb $wpdb WordPress database abstraction object.
    	 *
    	 * @param int $post_id Post ID.
    	 * @return WP_Post|false Post object, false otherwise.
    	 */
    	public static function get_instance( $post_id ) {
    		global $wpdb;

    		$post_id = (int) $post_id;
    		if ( $post_id <= 0 ) {
    			return false;
    		}

    		$_post = wp_cache_get( $post_id, 'posts' );

    		if ( ! $_post ) {
    			$_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) );

    			if ( ! $_post ) {
    				return false;
    			}

    			$_post = sanitize_post( $_post, 'raw' );
    			wp_cache_add( $_post->ID, $_post, 'posts' );
    		} elseif ( empty( $_post->filter ) || 'raw' !== $_post->filter ) {
    			$_post = sanitize_post( $_post, 'raw' );
    		}

    		return new WP_Post( $_post );
    	}

    	/**
    	 * Constructor.
    	 *
    	 * @since 3.5.0
    	 *
    	 * @param object $post Post object.
    	 */
    	public function __construct( $post ) {
    		foreach ( get_object_vars( $post ) as $key => $value ) {
    			$this->$key = $value;
    		}
    	}

    	/**
    	 * Isset-er.
    	 *
    	 * @since 3.5.0
    	 *
    	 * @param string $key Property to check if set.
    	 * @return bool
    	 */
    	public function __isset( $key ) {
    		if ( 'ancestors' === $key ) {
    			return true;
    		}

    		if ( 'page_template' === $key ) {
    			return true;
    		}

    		if ( 'post_category' === $key ) {
    			return true;
    		}

    		if ( 'tags_input' === $key ) {
    			return true;
    		}

    		return metadata_exists( 'post', $this->ID, $key );
    	}

    	/**
    	 * Getter.
    	 *
    	 * @since 3.5.0
    	 *
    	 * @param string $key Key to get.
    	 * @return mixed
    	 */
    	public function __get( $key ) {
    		if ( 'page_template' === $key && $this->__isset( $key ) ) {
    			return get_post_meta( $this->ID, '_wp_page_template', true );
    		}

    		if ( 'post_category' === $key ) {
    			if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) {
    				$terms = get_the_terms( $this, 'category' );
    			}

    			if ( empty( $terms ) ) {
    				return array();
    			}

    			return wp_list_pluck( $terms, 'term_id' );
    		}

    		if ( 'tags_input' === $key ) {
    			if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) {
    				$terms = get_the_terms( $this, 'post_tag' );
    			}

    			if ( empty( $terms ) ) {
    				return array();
    			}

    			return wp_list_pluck( $terms, 'name' );
    		}

    		// Rest of the values need filtering.
    		if ( 'ancestors' === $key ) {
    			$value = get_post_ancestors( $this );
    		} else {
    			$value = get_post_meta( $this->ID, $key, true );
    		}

    		if ( $this->filter ) {
    			$value = sanitize_post_field( $key, $value, $this->ID, $this->filter );
    		}

    		return $value;
    	}

    	/**
    	 * {@Missing Summary}
    	 *
    	 * @since 3.5.0
    	 *
    	 * @param string $filter Filter.
    	 * @return WP_Post
    	 */
    	public function filter( $filter ) {
    		if ( $this->filter === $filter ) {
    			return $this;
    		}

    		if ( 'raw' === $filter ) {
    			return self::get_instance( $this->ID );
    		}

    		return sanitize_post( $this, $filter );
    	}

    	/**
    	 * Convert object to array.
    	 *
    	 * @since 3.5.0
    	 *
    	 * @return array Object as array.
    	 */
    	public function to_array() {
    		$post = get_object_vars( $this );

    		foreach ( array( 'ancestors', 'page_template', 'post_category', 'tags_input' ) as $key ) {
    			if ( $this->__isset( $key ) ) {
    				$post[ $key ] = $this->__get( $key );
    			}
    		}

    		return $post;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-post.php#L21)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-post.php#L21-L388)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 6 content](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#comment-content-1971)
 2.    [Priyanka Behera](https://profiles.wordpress.org/priyankabehera155/)  [  9 years ago  ](https://developer.wordpress.org/reference/classes/wp_post/#comment-1971)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%23comment-1971)
     Vote results for this note: 7[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%23comment-1971)
 4.  _**Please Note:**_ _While the above method is fine for retrieving the post ID,
     you should not use the above method for displaying post\_content and other filtered
     elements (such as post\_title)._ You should instead use either the_content if 
     you are in the loop, or apply_filters if outside the loop, so it would look like
     this
 5.      ```php
         $examplePost = get_post();
     
         echo $examplePost->post_content; // Don't do this
     
         echo apply_filters( 'the_content', $examplePost->post_content ); // Do this instead
         ```
     
 6.   * If you do not have any shortcodes in your post content, then no need to parse
        though the `the_content` filter.
      * [Aurovrata Venet](https://profiles.wordpress.org/aurovrata/) [5 years ago](https://developer.wordpress.org/reference/classes/wp_post/#comment-4918)
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%3Freplytocom%3D1971%23feedback-editor-1971)
 8.   [Skip to note 7 content](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#comment-content-1970)
 9.    [Priyanka Behera](https://profiles.wordpress.org/priyankabehera155/)  [  9 years ago  ](https://developer.wordpress.org/reference/classes/wp_post/#comment-1970)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%23comment-1970)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%23comment-1970)
 11. **To access the member functions of the post object, use this syntax.**
 12.     ```php
         $examplePost = get_post();
     
         echo $examplePost->ID; // Display the post's ID
         ```
     
 13.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%3Freplytocom%3D1970%23feedback-editor-1970)
 14.  [Skip to note 8 content](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#comment-content-4223)
 15.   [Lovro Hrust](https://profiles.wordpress.org/lovor/)  [  6 years ago  ](https://developer.wordpress.org/reference/classes/wp_post/#comment-4223)
 16. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%23comment-4223)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%23comment-4223)
 17. I found a longer list of member variables for [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
     object than documented above, at least for menu item [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
     object and WordPress v5.5.1. Additional variables are:
 18. Member variable Variable type
 19. to_ping string
      pinged string post_content_filtered string guid string post_mime_type
     string filter string db_id integer menu_item_parent string object_id string object
     string type string type_label string url string title string
 20.  * url (string) and classes (string?) are still being used by twentytwenty theme
        at inc/template-tags.php of wordpress 6.0
      * [randompage](https://profiles.wordpress.org/randompage/) [4 years ago](https://developer.wordpress.org/reference/classes/wp_post/#comment-5868)
 21.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%3Freplytocom%3D4223%23feedback-editor-4223)
 22.  [Skip to note 9 content](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#comment-content-7384)
 23.   [Aurovrata Venet](https://profiles.wordpress.org/aurovrata/)  [  9 months ago  ](https://developer.wordpress.org/reference/classes/wp_post/#comment-7384)
 24. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%23comment-7384)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%23comment-7384)
 25. `
      [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/) Object([
     ID] => 4685 [post_author] => 3 [post_date] => 2010-07-01 00:00:00 [post_date_gmt]
     => 2025-07-24 05:43:52 [post_content] => [post_title] => (PRESENTATION) Research,
     Analysis, and Design. [post_excerpt] => [post_status] => publish [comment_status]
     => open [ping_status] => closed [post_password] => [post_name] => presentation-
     research-analysis-and-design [to_ping] => [pinged] => [post_modified] => 2025-
     09-03 13:02:22 [post_modified_gmt] => 2025-09-03 13:02:22 [post_content_filtered]
     => [guid] => [https://example.com/?post_type=post&p=4685](https://example.com/?post_type=post&p=4685)[
     menu_order] => 0 [post_type] => post [post_mime_type] => [post_parent] => 0 [comment_count]
     => 0 [filter] => raw [page_template] => default ) `
 26.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%3Freplytocom%3D7384%23feedback-editor-7384)
 27.  [Skip to note 10 content](https://developer.wordpress.org/reference/classes/WP_Post/?output_format=md#comment-content-7497)
 28.   [jesus0903](https://profiles.wordpress.org/jesus0903/)  [  2 months ago  ](https://developer.wordpress.org/reference/classes/wp_post/#comment-7497)
 29. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%23comment-7497)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%23comment-7497)
 30. Although “GUID” stands for Globally Unique Identifier, WordPress does not enforce
     a uniqueness constraint on the database level. In some cases—particularly when
     using plugins that publish posts without going through a draft state—multiple 
     posts may share the same GUID value.
 31. You should not use the GUID as a unique key for querying posts. Instead, use the
     post ID to guarantee uniqueness.
 32.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F%3Freplytocom%3D7497%23feedback-editor-7497)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_post%2F)
before being able to contribute a note or feedback.