What is the method to test for the existence of an option in the database?
Not the value of the option, just that the option exists.
What is the method to test for the existence of an option in the database?
Not the value of the option, just that the option exists.
Options that don’t exist get the fact of their non-existence cached in memory when you attempt to get them. So you can check that cache to determine the difference.
$value = get_option('example');
$notoptions = wp_cache_get( 'notoptions', 'options' );
if ( isset( $notoptions['example'] ) ) {
// option does not exist
} else {
// option exists, $value is legit
}