Display Custom Fields In & Out of The Loop

INSIDE THE LOOP:

<?php

if ( get_post_meta($post->ID, 'custom-field-name', true) ) :
	echo get_post_meta($post->ID, 'custom-field-name', true);
	endif;

?>

OUTSIDE THE LOOP:

<?php

	global $wp_query;
	$postid = $wp_query->post->ID;
	echo get_post_meta($postid, 'custom-field-name', true);
	wp_reset_query();

?>

Leave a Comment