get_post_meta() should only return false under a couple of circumstances:
269 function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) { 270 if ( !$meta_type ) 271 return false; 272 273 if ( !$object_id = absint($object_id) ) 274 return false;https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/meta.php#L269
I don’t see how $meta_type could be wrong since it is hard-coded into get_post_meta():
1769 function get_post_meta($post_id, $key = '', $single = false) { 1770 return get_metadata('post', $post_id, $key, $single); 1771 }https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/post.php#L1769
That leaves $object_id. Something could be passing an bad object ID– something like this…
$object_id = 'abc';
// or this
// $object_id = -123;
var_dump(!$object_id = absint($object_id));
… will evaluate true causing get_post_meta to return false.
Another possibility is that a filter is returning a problematic value here:
276 $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single ); 277 if ( null !== $check ) { 278 if ( $single && is_array( $check ) ) 279 return $check[0]; 280 else 281 return $check; 282 }
If some filter sets $check to an array with false as the only element, then null !== $check is true and that array gets returned. For example:
add_filter(
'get_post_metadata',
function($meta) {
return array(false);
}
);
$t = get_post_meta(1,'_edit_lock_dood',false);
var_dump($t,empty($t));
Note: simply returning false from that filter won’t do it. It must be an array with false as the single element, which gets to the technical reason your code doesn’t work.
empty(false) is true but empty(array(false)) is false— the array is not empty. It has an element, even though that element is false. Play with var_dump() a bit and you can demonstrate it for yourself. Like this, for example:
$a = array(false);
var_dump($a);
var_dump(empty($a));
There is not enough context to your question/code for me to narrow it down further.