$post global variables represents the current post in the Wordpress loop. It is set in the method the_post() of the the class WP_Query defined in [wordpress root folder]/wp-includes/classes.php. This method has a wrapper in form of a global function the_post() defined in [wordpress root folder]/wp-includes/functions.php. This global function is invoked as part of the Wordpress Loop.
The theme authors need not use this global variable directly. Wordpress provides functions to display the post data inside the loop.
- the_ID()
the_title(): displays titlethe_content(): displays the post contentthe_excerpt(): displays the excerptthe_attachment_link(): displays the attachment link- the_meta(): displays the post metadata which comprises the post custom fields
These functions display the values after applying filters. To access them for custom processing Wordpress provides get_ equivalents of the functions mentioned above, which takes the post ID as the parameter, e.g., get_the_title($id) which will return title of the specified post.
To access the post custom fields following functions are provided:
get_post_custom_keys(): returns an array of keys of all the custom fields.get_post_custom_values($key = ''): returns arrays of values of custom fields with specified keyget_post_meta($post_id, $key, $single = false): returns value of the specified custom field key for specified post_id
Back to full list of global variables.
Technorati tags: post, display post, custom fields, the loop

June 8th, 2006 at 9:31 pm
[...] $post [...]
October 20th, 2007 at 10:16 pm
[...] variable that holds a reference to the current post being displayed. This is further explained at ifacethoughts, but in short it means access to all sorts of [...]