When using the ==
comparison, it compares the values at the same type. So 1
is equal to "1"
, and true
. Likewise, 0
is equal to false
.
Taking a deeper look into the return values of get_post_meta
, we can see that using the $single=true
3rd argument returns a blank string (''
) when no value is found, not false
. So you should be checking to make sure THAT isn’t the case.
$post_meta_h = get_post_meta( $post->ID, 'stat_red_h', true );
$post_meta_a = get_post_meta( $post->ID, 'stat_red_a', true );
if( $post_meta_h !== '' || $post_meta_a !== '' ) {
// do something
}
Let me know if this doesn’t work for you.