empty
checks for several things:
- “” (an empty string)
- 0 (0 as an integer)
- 0.0 (0 as a float)
- “0” (0 as a string)
- NULL
- FALSE
- array() (an empty array)
- $var; (a variable declared, but without a value)
In short, you are running a check if the value evaluates to false or does the value evaluate to true. Either way it will always evaluate to true.
Now I don’t know what the function vf_get_meta
returns for empty values. If you look at core get_post_meta
function, it returns either an empty array or an empty string when the single flag is set to true.
I think the best rewrite will be this:
if ( vf_get_meta($post->ID, 'page_options', 'show_title') !== false )
We are saying, as long as it is not set to false
, do it. You’ll notice that I used !==
instead of !=
. The !==
is the “Not Identical” comparison instead of the !=
“Not Equal”. PHP will convert certain values into a boolean true
or false
for the equality comparison. Sometimes you’ll hear people say a value is “truthy” or “falsey” reflecting how it will be convert to a boolean value.