I created a plugin that is used on every site within my Multisite setup. Within this plugin I have an admin setting page that allows each site to set the options according to the sites needs. Each site saves its data with the add_option()
function.
How do I query all the custom options values from all the sites on the Multisite? I need to collect the values and then store them into an array. Once in an array I will be using it to check another value with the array to see if it exist within the array of option values from all the sites.
How to find all the values of the custom options?
You can use get_site_option() function to get single network-wide option.
Example :
If you want to get all options from all sites use wp_load_alloptions() function.
Example :
So this is what I came up with and it works, but if there is a more efficient way of getting the same results (like a built in WP function) then please let me know. Thanks.
Thanks for the response, but wp_load_alloptions() is only returning all options and values from a the single site that it is loaded on and not all the options and values from all the sites on the network.
What I need is something like below where I copied from wp_load_alloptions() core and added the WHERE clause. However this returns only the site option specific to where it is executed, because the $wpdb prefix calls for the site that is ran.
$alloptions_db = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE option_name = 'NAME_OF_OPTION'");