Custom field outside loop

Custom fields are definitely very useful and are used on many WordPress-powered blogs. In this recipe, I’m going to show you how to easily get custom fields values outside the loop. Adding this code snippet to your wordpress theme:






global $wp_query;
$postID = $wp_query->post->ID;
echo get_post_meta($postID, 'CUSTOM-FIELD-NAME', true);

Leave a comment