ifacethoughts

post

$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 title
  • the_content(): displays the post content
  • the_excerpt(): displays the excerpt
  • the_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 key
  • get_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: , , ,

Discussion [Participate or Link]

  1. Abhijit Nadgouda @ iface » Blog Archive » Wordpress Global Variables said:

    […] $post […]

  2. scompt.com » Adding custom columns to the WordPress manage posts screen said:

    […] 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 […]

  3. Mark Bethke said:

    Put a Paypal button on your site to buy you a drink of your choice and I will click on it! I thought Linux was brutal for documentation but the new leader in mis-information, badly documented or out and out wrong has got to be WordPress!

Say your thought!

If you want to use HTML you can use these tags: <a>, <em>, <strong>, <abbr>, <code>, <blockquote>. Closing the tags will be appreciated as this site uses valid XHTML.

freshthoughts

contactme

Abhijit Nadgouda
iface Consulting
India
+91 9819820312
My bookmarks

badgesand...

This is the weblog of Abhijit Nadgouda where he writes down his thoughts on software development and related topics. You are invited to subscribe to the feed to stay updated or check out more subscription options. Or you can choose to browse by one of the topics.