wp_load_alloptions()
Loads into cache all auto-loaded options of WordPress. Retrieves all options of the site.
If there are no auto-loaded options, then load all options.
The label indicating whether the option is auto-loaded is set when adding the option or when updating it in the parameter $autoload:
add_option( $name, $value, $deprecated, $autoload ); // or update_option( $option_name, $newvalue, $autoload );
This function is called automatically at an early stage of loading WordPress. It loads all options from the wp_options table. Later, when we retrieve an option using get_option(), the option is taken from the cache, not from the database.
The function caches the result of its work, so the first call to the function takes a long time, while all subsequent calls are very fast.
Hooks from the function
Returns
Array. An array of all options loaded into cache. Where the key is the option name, and the value is the option value.
Usage
$alloptions = wp_load_alloptions();
Examples
#1 Get all the site options
$alloptions = wp_load_alloptions();
As a result $alloptions will contain such an array:
Array ( [siteurl] => http://wp-kama.com/ [blogname] => WordPress as in the palm of your hand [blogdescription] => Features, hacks, and articles for beginners [users_can_register] => 1 [admin_email] => [email protected] [start_of_week] => 1 [use_balanceTags] => [require_name_email] => 1 [comments_notify] => [posts_per_rss] => 15 [rss_use_excerpt] => 1 [default_category] => 1 [default_comment_status] => open [default_ping_status] => open ...
#2 Get all transient options without timelimit
$all_options = wp_load_alloptions();
$all_transients = array();
foreach ( $all_options as $name => $value ) {
if ( strstr( $name, '_transient' ) ) {
$all_transients[ $name ] = $value;
}
}
print_r( $all_transients );
Notes
- Global. wpdb.
$wpdbWordPress database abstraction object.
Changelog
| Since 2.2.0 | Introduced. |
| Since 5.3.1 | The $force_cache parameter was added. |