If I call the following function (on a page template, e.g. page-home.php) before the loop, nothing is returned. If I call it during or after the loop, the expected values are returned. Is there a way to access these meta fields before the loop runs?
function home_content() {
global $post;
$headline = get_post_meta($post->ID, 'top-headline', true);
$body = get_post_meta($post->ID, 'top-body', true);
$return = '<h4>' . $headline . '</h4>';
$return .= '<p>' . $body . '</p>';
echo $return;
}
$post
doesn't contain anything until the loop runs. You can however check(i think)$posts
prior to when the loop runs.