Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Class Reference/WP Post

Role of WP_Post

The WP_Post class is used to contain post objects stored by the database and is returned by functions such as get_post.

Member Variables of WP_Post

As of WordPress Version 3.5.1

Member Variable Variable Type Notes
ID int The ID of the post
post_author string The post author's user ID (numeric string)
post_name string The post's slug
post_type string See Post Types
post_title string The title of the post
post_date string Format: 0000-00-00 00:00:00
post_date_gmt string Format: 0000-00-00 00:00:00
post_content string The full content of the post
post_excerpt string User-defined post excerpt
post_status string See get_post_status for values
comment_status string Returns: { open, closed }
ping_status string Returns: { open, closed }
post_password string Returns empty string if no password
post_parent int Parent Post ID (default 0)
post_modified string Format: 0000-00-00 00:00:00
post_modified_gmt string Format: 0000-00-00 00:00:00
comment_count string Number of comments on post (numeric string)
menu_order string Order value as set through page-attribute when enabled (numeric string. Defaults to 0)

Accessing the WP_Post Object

To access the member functions of the post object, use this syntax.

$examplePost = get_post();

echo $examplePost->ID; // Display the post's ID

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

$examplePost = get_post();

echo $examplePost->post_content; // Don't do this

echo apply_filters( 'the_content', $examplePost->post_content ); // Do this instead

Source File

WP_Post is located in wp-includes/class-wp-post.php.


See also index of Class Reference and index of Function Reference.