I'm writing a very simple function in Wordpress that outputs the contents of a location field.
It works in the template file, but when I put it into functions.php and call it from the template, it stops working.
function check_location() {
$location_field = get_post_meta($post->ID, 'location', true);
return $location_field;
}
I did a var_dump and it returns the $location_field as a string(0)
I've also tried declaring global $post in the function, but it makes no difference.
Does anybody know what could be wrong?