Get custom field outside the WordPress loop

Do you want to get a custom field outside the WordPress loop (e.g. in your sidebar) and you have no idea how? The following code snippet will help you do it.

* Replace the ‘customField’ in the 4th line with the name of your custom field.

<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'customField', true);
?>

Source: www.wprecipes.com/wordpress-how-to-get-custom-fields-outside-the-loop

CATEGORY: Code
DATE: October 29th, 2010 & LEAVE YOUR COMMENT HERE

FILTER BY

Colors