Codex tools: Log in
Contents |
The WP_Post class is used to contain post objects stored by the database and is returned by functions such as get_post.
As of WordPress 3.5.1
| Member Variable | Variable Type | Notes |
|---|---|---|
| ID | int | The ID of the post |
| post_author | int | The post author's user ID |
| 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 | int | Number of comments on post |
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 your 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
WP_Post is located in wp-includes/post.php.