get_site_meta()
Gets the value of the site's meta-field in a multisite network. Also allows retrieving all meta-fields.
Works with the wp_blogmeta table introduced in version 5.1.
This is a wrapper for the function get_metadata().
No Hooks.
Returns
Mixed.
If the value of the meta-field is an integer, it will be returned as a string, for example, "54"...
- Will return
falseif the $site_id is incorrect. - When $single = true
string/array— when the meta-field exists.''— when the meta-field does not exist.
- When $single = false
array of meta-field values— when the meta-field exists.array()— when the meta-field does not exist.
Usage
get_site_meta( $site_id, $key, $single );
- $site_id(integer) (required)
- ID of the site/blog.
- $key(string)
- Name of the meta-field. If this parameter is not specified, all values of all meta-fields of the object will be returned.
Default: '' - $single(true/false)
Should a single value be returned or not?
true— will return the value of the meta-field as a string or array (if the value of the meta-field contains a serialized array). If there are multiple meta-fields with the same key, the value of the first meta-field will be returned.false— will return an array with the values of all meta-fields of the specified key. In this case, all values will be strings, even when the value contains a serialized array (it needs to be manually converted to an array).Default: false
Examples
#1 Demo: retrieve site (blog) metadata
// get the meta field of the site with ID 17, directly in the variable $blog_meta = get_site_meta( 17, 'mykey', true ); // Get all values of the meta-field (with the same key) as an array $blog_meta = get_site_meta( 14, 'mykey' ); // Get all the metadata of the site with ID 115, as an array $blog_metas = get_site_meta( 115 );
#2 More examples
See get_post_meta().
Changelog
| Since 5.1.0 | Introduced. |
get_site_meta() get site meta code WP 6.9.1
function get_site_meta( $site_id, $key = '', $single = false ) {
return get_metadata( 'blog', $site_id, $key, $single );
}