Wordpress $post Variable Quick Reference

Summary:
This is a quick reference chart for the Wordpress $post array. The post array holds things like the post title, number of comments, status, date and time of last modification, and numerous other attributes.
buzz_button

This quick reference is for the Wordpress $post array. This array contains a bunch of info specific to each Wordpress post. 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 value 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;
?>

I haven’t worked out some of the values in the chart below, so if you know what any of those missing values refer to, let me know.

Excel download icon
Download the spreadsheet

 
Bookmark and Share

11 Comments so far ↓

  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. dizastix says:

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

  5. Markus says:

    Thanks for this summary – saved me big time :)

  6. Phil Freo says:

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

  7. d says:

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

    this is how wordpress holds images

  8. max says:

    I love you for this post.

  9. Peter says:

    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. mash says:

    looking for a list of keys for this array.

    anyone?


Leave a Reply

Email is required but will not be published. All comments are moderated and no-followed. Please do not use keywords or domains as names and do not advertise.