InMotion Hosting Support Center

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();
echo $example->post_title;

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.

Was this article helpful?

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

n/a Points
2017-04-11 4:01 pm
I want to show content from a specific post (with the Featured Image thumbnail) in my custom sidebar. Where can I find the code for this?
10,511 Points
2017-04-11 4:06 pm
The WordPress function reference is well documented, and it is definitely the best place to start.

Post a Comment

Email Address:
Phone Number:

Please note: Your name and comment will be displayed, but we will not show your email address.

2 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!