If you are a WordPress developer you might have found the need to access information that is not readily accessible via the template tags. So before you go and create a complicated function, take a look at the list below. This list of WordPress $post variables shows the information that you can retrieve while in the Loop. Using these variables will enable greater flexibility in your WordPress themes, functions, and plugins.
Below are the methods of retrieving the information that you are most likely to need.
The $post variable contains an array of post content. As shown above, we are able to retrieve specific content by using a key. If you want to retrieve this content in your loop, take a look at the sample code below where the post content is retrieved and stored in $yourvariable.
<?php if (have_posts()) : while (have_posts()) : the_post();
//somewhere in the loop
$yourvariable = $post->post_content;
//do something
endwhile; endif; ?>
This is a simplified version, but it will work in any case, as well as with custom loops using get_posts() or query_posts(). For these loops, however, it will probably be necessary for you to ensure that all post data can be accessed. This is done by using a special WordPress function called setup_postdata(). And it should be called before any $post data is accessed. See its usage below.
setup_postdata($post);
We have omitted a few variables, namely those relating to pinging and commenting. Let us know if we should add anything else to our list.
Tags: PHP, WordPressTrackback URL for this entry:
http://www.velvetblues.com/web-development-blog/wordpress-post-variable-reference/trackback/
Contact us today for a quote. Click here to submit details regarding your project.
If you are making a general inquiry, send an email to info@velvetblues.com
Thanks for the great reference!