When using WordPress functions such as get_post(), the information will be stored within WP_Post objects. In this article, we will show you what is stored within those WP_Post objects, as well as how to access them.
If you would like more information on creating WordPress plugins, see our tutorial series on creating your first WordPress plugin.
Variables stored within WP_Post objects
ID: This variable stores the post's ID.
post_author: This variable stores the post author's numeric user ID.
post_type: This variable contains the post's type.
post_title: This variable stores the title of the post.
post_date: This variable displays the date and time of the post.
post_date_gmt: This variable displays the same content as post_date, but in GMT.
post_content: This variable stores the content of the post.
post_excerpt: This variable stores the user-defined excerpt of the post.
post_status: This variable stores the post's current status.
comment_status: This variable stores information on whether the comments are open or closed on the post.
ping_status: This variable stores information on whether the post is open or closed for pingbacks.
post_password: This variable stores the post's password. It will return empty if the post does not have a password.
post_parent: If the post has a parent post, this variable will return the ID of the parent post.
post_modified: This variable stores the date and time that the post was last modified.
post_modified_gmt: This variable stores the last modified date and time in GMT.
comment_count: This variable stores the number of comments that have been left on the post.
menu_order: If a menu order is defined for the post, it will display it in this variable.
Getting data from WP_Post objects
Getting information from WP_Post objects is quite simple:
$example = get_post();
In this example, we are storing information from the get_post() function to the $example variable. As the get_post() function stores data using WP_Post objects, the $example variable now contains WP_Post objects.
Next, we simply call the desired WP_Post object from inside the $example variable and display it using the echo PHP command.