WordPress wp_load_alloptions()
function returns an associative array. This associative array contains WordPress options and transients whose autoload
property is set to true. By default all options and transients have autoload
property set to true. WordPress does let you set a option’s autoload
property to false.
The purpose of this function is the load all the keys-values in object cache which are used in almost all page requests.
Internally before wp_load_alloptions()
function tries to query mysql database it checks if an alloptions
key is present in WordPress object cache. If its present there then this function just returns the value(an array) associated with the key. If alloptions
key is not found in object cache then this function fetches the options and transients(with autoload
property set to true) from MySQL and then creates a array from the returned rows. Before returning the array it sets the alloptions
key in object cache with the created array as value. So that when next time its called it doesn’t have to fetch all key-value pairs from SQL which is an very expensive task.
This function is used by WordPress Options API and Transients API. Before they search for keys, add keys or update keys in object cache and/or MySQL they use the array returned by this function. While updating, deleting and adding keys WordPress options and transients API update the alloptions
key too to keep it updated. Remember that its only updated if the options or transients have autoload
property set to true.
Note: If wp_load_alloptions()
doesn’t find keys in options table with autoload
property set to true then it retrieves all the key-value pairs.