I think it must be pretty basic question but I am only starting. Can someone have a look at the 3 versions of the same (?) code below and say what the difference is? All of them seem to work fine in the loop I am working on.
Which should be used: $post->ID
, $the_ID
or get_the_id()
?
Is it necessary to have global $post;
?
global $post;
$content = get_post_meta( $post->ID, ‘my_custom_field', true );
echo $content;
or
$content = get_post_meta( $the_ID, ‘my_custom_field', true );
echo $content;
or
$content = get_post_meta( get_the_id(), ‘my_custom_field’, true );
echo $content;
Many thanks for your help