As stated by Tom, in the comments on the question, it seems not likely that WordPress will change their standard for storing/returning boolean post meta, due to backward compatibility issues. However, I thought of some ways to write code that will work even if the WordPress standard does change their standard:
- Always convert Boolean Post Meta data to it’s exact boolean value using the php
boolval
function. e.g.,boolval( get_post_meta( $id, 'my_boolean_post_meta', true ) );
. If so, it will now work to do strict comparisons totrue
orfalse
. - Utilize some other post meta data type like
string
orinteger
to implement boolean variables. Choose your own standards for what value will be true and false. Then define them as global constants.
BTW, even though WordPress stores true
as ‘1’ and false
as ”, the following meta queries still work (at least up to version 5.7.2):
For getting true values:
array(
'key' => 'my_boolean_post_meta',
'value' => true,
'compare' => '=',
),
For getting false values:
array(
'key' => 'my_boolean_post_meta',
'value' => false,
'compare' => '=',
),
It seems 'compare' => '='
does not result in a strict comparison.