WordPress Snippets at WPcustoms

Show custom meta fields outside the loop

Use this WordPress snippet to display a custom meta field outside the loop in your theme. You can also modify the $postID to show a custom field from a specific post.


/**
 * Snippet Name: Show custom meta fields outside the loop
 * Snippet URL: http://www.wpcustoms.net/snippets/show-custom-meta-fields-outside-loop/
 */
 global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'Your-Custom-Field', true);
wp_reset_query();