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.

3 Answers
3

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
}

Leave a Reply

Your email address will not be published. Required fields are marked *