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.

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:

<?php
$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.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

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

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

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

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

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: support@InMotionHosting.com
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!