get_site_transient()
Gets the value of the temporary option of the main site in the network.
If object caching is used on the site, the temporary options will be retrieved from the cache; otherwise, the data is obtained using get_site_option() (see the logic in the description).
Use the function get_transient() when you need to get the temporary option of the current site, not the main site in the network.
The difference between get_transient() and get_site_transient() is the same as between get_option() and get_network_option().
Hooks from the function
Returns
Mixed.
-
false is returned in the following cases:
- if the temporary option does not exist
- or it has an empty value
- or it has expired.
- In other cases, it returns the obtained option value.
Note: the returned false should be checked with strict equality (===), not regular double equality, because the option value may contain 0 or an empty string, an empty array. For this reason, do not save false in the option value; instead, save 0 or place false in an array.
Usage
get_site_transient( $transient );
- $transient(string) (required)
- The name of the temporary option.
Examples
#1 Example of use
Suppose we have data that is used on all sites on the network. This data needs to be retrieved by HTTP request from another site, so it is good to cache this request. This function will be good for this purpose. The logic of such code is shown below:
$transient = 'some_trans_name';
$remote_data = get_site_transient( $transient );
if( false === $remote_data ){
$remote_data = file_get_contents( 'http://dom.ru/promo/yith-promo.xml' );
}
if( $remote_data ){
set_site_transient( $transient, $remote_data, WEEK_IN_SECONDS );
}
Notes
- See: get_transient()
Changelog
| Since 2.9.0 | Introduced. |