WordPress $post Object Quick Reference

This quick reference / cheatsheet is for the WordPress $post object. This object contains a bunch of info specific to each WordPress post. Scroll down for the complete table of object properties.

Download Printable versions (PDF)

Landscape Orientation (pdf) Portrait Orientation (pdf)

How to use the $post object

The values in the chart below can be accessed for a given post within the loop using the following syntax:

$post->$key;

…where key is the property you want to access below. For example, you’ll notice at the top of this post is a post summary within a formatted div element. The summary is just a formatted version of the post excerpt, but if there’s no post excerpt I don’t want that div element showing up empty, so in that case, I hide it using the following code:

<?php
if($post->post_excerpt != '') :
    echo '<div id="summary">';
    echo '<strong>Summary:</strong><br />';
    the_excerpt();
    echo '</div>';
endif;
?>

$post Object properties

Property Sample Value Notes
post_author 1 Post author’s user number
post_date 2008-03-15 19:22:29
post_date_gmt 2008-03-16 02:22:29 GMT = Greenwich Mean Time
post_content Actual post content, including markup
post_title Post title
post_category 0 Number representing post category ID#
post_excerpt Plain text without markup
post_status publish, pending, draft, private, inherit Current status of the post
comment_status open Possible values: open / closed
ping_status open open / closed
post_password Will be empty if no password
post_name statistics Same as post slug
to_ping http://www.1to-ping.com, http://www.2to-ping.com, http://www.3to-ping.com List of urls to ping when post is published (for unpublished posts)
pinged http://www.pinged1.com, http://www.pinged2.com, http://www.pinged3.com List of urls that have been pinged (for published posts)
post_modified 2008-07-01 19:41:28 Date the post was last modified
post_modified_gmt 2008-07-02 02:41:28 GMT date post was last modified
post_content_filtered Exists to store a cached version of post content (most likely with all the the_content filters already applied). If you’ve got a plugin that runs a very resource heavy filter on content, you might consider caching the results with post_content_filtered, and calling that from the front end instead.
post_parent ID# of this post’s parent. In the case of attachments, will be the post it’s attached to. Defaults to 0 if no parent.
guid http://www.blogurl/postslug Global Unique Identifier. The “real” URL to the post, not the permalink version. For pages, this is the actual URL. In the case of files (attachments), this holds the URL to the file.
menu_order 0
1
2
etc…
Holds values for display order of pages. Only works with pages, not posts.
post_type page
post
attachment
revision
Self-explanatory for pages and posts. Any files uploaded are attachments and post revisions saved as revision
post_mime_type text/html
image/png
image/jpg
Only used for files (attachments). Contains the MIME type of the uploaded file.
comment_count 4 Number of comments, pings, and trackbacks combined

Thanks to everyone who commented on this post to help fill in some of the missing values!

image_pdfimage_print
21 Comments
  1. guid stands for global unique identifier. i think, they just say that an url identifies an object and this object is identified by exactly one url, if itis normalized.

  2. Thanks Thomas! I’ll get that added

  3. saved me, thanks dude!!!!!

  4. Thanks a lot for this reference! helped me figure out a problem that was taking me hours.

  5. Thanks for this summary – saved me big time :)

  6. post_parent should give you the ID of a subpage’s parent page.

  7. post_type can also be “attachment”, post_status will be “inherit” then..

    this is how wordpress holds images

  8. I love you for this post.

  9. This is a great resource, I’m eternally forgetting what the variable that I’m after is called. A couple of points:

    post_guid does indeed hold the url to the post, but it is the REAL url (not the permalink version), so if you’re linking to it from within the site, use get_permalink(), not guid.

    menu_order holds the values for display order of pages (only works with pages, not posts).

    post_content_filtered exists to store a cached version of post content (most likely with all the the_content filters already applied). If you’ve got a plugin that runs a very resource heavy filter on content, you might consider caching the results with post_content_filtered, and calling that from the front end instead.

  10. looking for a list of keys for this array.

    anyone?

  11. Great post – but the Excel file seems to have gone missing!

  12. My man… HUGE!!! Thanks so much for the help! Took me a while to figure out how to echo the title post inside a php query, thanks agin!

  13. for sure a good resource. However, could anyone please be so kind to list down available variables in “Post” array or “key”? I have been struggling finding a way to extract post title and then manipulate it…

    thanks in advance for helping.

  14. useful list except i see no property for a post’s permalink. this would be a pretty essential one especially in custom loops for short code functions since they must return a string so have html show up in the right location of a post.

    it must exist since inside a loop using WP_Query you can execute the_permalink()

    Help?

  15. after some research – doesn’t exist but you can do:

    $link = get_permalink($post->ID);
    :)

  16. What about post’s tag name ?

Leave a Reply

Address

Razorlight Media
Phone: 513-549-7355
Fax: 866-377-4331
Url:
cash, check, credit card, invoice, paypal
2207 Kemper Lane
Cincinnati, OH 45206
700 West Pete Rose Way, Suite 554
Cincinnati, OH 45203