The solution you used seems correct. But if you still want to know alternatives, here it is:
$varname = get_post_meta($post_id, 'fieldname', true);
echo $varname;
$varname
will be an array if the last parameter is false
and will be the value of metadata field if the last parameter is true
.
You can use the_field()
as well which works similar to get_field()
you used.