• Resolved o0TarZan0o

    (@o0tarzan0o)


    As we known, get_option($tag) was used to get value from wp_options table. However, in some cases, get_option() was used to push value to variable?!

    $msg = get_option('hello_world');
    echo $msg;

    Clearly, hello_world never exist in wp_options table, that’s second feature of get_option, huh?

Viewing 6 replies - 1 through 6 (of 6 total)
  • var_dump($msg) returns false. What you are doing does not set $msg to “hello_world”.

    Thread Starter o0TarZan0o

    (@o0tarzan0o)

    Nothing to say if I type $msg = ‘hello_wordld’; I only want to know more about get_option tag. Thanks ??

    I just told you about the get_option(...) function. If there is no ‘hello_world’ key in the wp_options table, the function returns false. It does not “push value to variable”, though it looks like you can use a second parameter for that.

    https://codex.www.ads-software.com/Function_Reference/get_option

    Thread Starter o0TarZan0o

    (@o0tarzan0o)

    Updating key in wp_options is developer job (not client). In some themes, it’s used to check conditional. Ex:

    function version_init() {
    
        $framework_version = '1.0';
    
        if ( get_option( 'framework_version' ) != $framework_version ) {
        update_option('framework_version', $framework_version );
        }
    }

    Why they can compare get_option(‘framework_version’) with another value while framework_version key don’t exist in wp_options table.

    Like I said, get_option(...) will return false if the key doesn’t exist. false does not equal any value that $framework_version might be (except false and 0), therefore the conditional as a whole is true and update_option runs.

    The result is that the first time this runs, it will insert the ‘framework_version’ into wp_options. After that it will simply update ‘framework_version’.

    Thread Starter o0TarZan0o

    (@o0tarzan0o)

    I had received enthusiasm help from you, thanks so much!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Having trouble with get_option tag’ is closed to new replies.