Support » Networking WordPress » get_site_option always returns false

  • Resolved rhj4

    (@rhj4)


    all calls to get_site_option return false, even when the data is clearly present in the database in the corresponding wp_#_options table.

    Update_site_option is saving the data correctly, but get_site_option cannot find what update_site_option just saved.

    My code is:

    $options = (is_multisite())
                ? get_site_option($this->option_name)
                : get_option($this->option_name);

    where “$this->option_name” exactly matches the option_value from the wp_#_options table.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I would spread a few debug outputs in the code, like:

    echo 'Fetched option: ';
    print_r( $this->option_name );
    print_r( $options );

    What does this tell you ?
    Maybe you have to workout some other way to view this output.

    I have spread diagnostics all over the place. The problem is that the behavior of get_option and get_site_option is not clear or consistent. This post sheds some clarity on the issue, but I am still getting results I don’t understand.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    Lead Plugin Wrangler

    Please try to use code tags when posting code 🙂

    You;re using this wrong. get_site_option is (stupidly named) for the network, NOT the individual site.

    https://codex.wordpress.org/Function_Reference/get_site_option

    It is easy to get confused about the difference between get_option() and get_site_option(), because multisite used different terms before. Now there are different “sites” on a “network”, before there where different “blogs” on a “site”. Many functions and variables were introduced before this change, such as this one. Think of this function as “get_network_option()”.

    get_site_option pulls its values from wp_sitemeta. What I want is the value in wp_$blog_id_options and get_option seems to be the way to get that.

    I believe that you are the expert, but what seems to be working for me seems to be the reverse of what you are telling me.

    What am I missing?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    Lead Plugin Wrangler

    Well… ythat depends.

    $options = (is_multisite())
                ? get_site_option($this->option_name)
                : get_option($this->option_name);

    That’s saying if this is multisite, then get_site_option (i.e. the network option), otherwise get_option

    Don’t you always want to get the option from the actual site and, if so, just call get_option all the time.

    The answer to my question (after many emails and tests is:

    To set/get an option that is specific to a single site in the network, use get_option / update_option.

    To set/get an option that is common to all sites in the network, use get_site_option / update_site_option.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘get_site_option always returns false’ is closed to new replies.