EDIT: I believe my confusion is probably created by this code at the top of the page in which I’m testing for the value of the option… This creates a shortcut method to refer to the option without using the get_option(‘option’) method…
global $options;
foreach ($options as $value) {
if (get_settings( $value['id'] ) === FALSE) {
$$value['id'] = $value['std'];
} else {
$$value['id'] = get_settings( $value['id'] );
}
}
And so when I set the value of a variable, $myvar, via a checkbox checked in my theme’s options panel and click save, then view my options.php in worpdress, the value of the variable is
true
And when I do a lookup on this variable using
if($myvar == "true")
It passes.
However, when I set the value directly via the update_options() method, like so…
$mvar = true;
update_option('myvar', $myvar);
The value changes from true to 1
And when I do the same comparison as before, if($myvar == “true”), it now fails. It is no longer “true”.
What am I missing? (1) why is “true” and 1, not evaluating the same and (2) What is the update_option method doing to the value of myvar to change the value from true to 1?
Try
and
TRUEandFALSEare PHP’s built in boolean variables which are much more universal than a true string.About the update_option. It might not be that the option is changing it to 1. Instead it might be that the when it is inserting it into the database, it inserts it as the string
"true". Then, when it comes back it is converted to the boolean valuetrue, which when printed is1