You are trying to get the values from the current post? or are you trying to get the values from some specific post?
If it’s from the current post, the reason that the above isn’t working is probably because it’s in a function? and inside a function the values used to create a post loop don’t exist.
Try adding this to the top of your function
global $wp_query, $post;