How to get custom values outside Loop


 How to get custom values outside Loop

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

Example:

<?php 
global $wp_query;
$postid = $wp_query->post->ID;
$img = get_post_meta($postid, 'sidebar_image', true);
if($img)
{
echo "<img src ='$img'>";
}
else{
?>
<img src="<?php bloginfo("template_url")?>/images/care.jpg" />
<?php
}
wp_reset_query();
?>

2 thoughts on “How to get custom values outside Loop

  1. Appreciate it for helping out, good information. “Job dissatisfaction is the number one factor in whether you survive your first heart attack.” by Anthony Robbins.

Comments are closed.