函数文档

get_site_meta()

💡 云策文档标注

概述

get_site_meta() 函数用于检索 WordPress 多站点中指定站点的元数据。它基于 get_metadata() 实现,支持通过参数控制返回单个值或所有键的数组。

关键要点

  • 函数用于获取站点元数据,仅适用于多站点环境。
  • 参数包括 $site_id(必需)、$key(可选,默认为空返回所有键)和 $single(可选,控制是否返回单个值)。
  • 返回值根据参数和条件变化:可能返回数组、单个值、false(无效站点ID时)、空数组或空字符串。
  • 非序列化值以字符串形式返回,如 false 返回空字符串,true 返回 '1',数字返回字符串,数组和对象保持原类型。

代码示例

function get_site_meta( $site_id, $key = '', $single = false ) {
    return get_metadata( 'blog', $site_id, $key, $single );
}

注意事项

  • 此函数仅在多站点博客中可用,单站点环境可能不支持。

📄 原文内容

Retrieves metadata for a site.

Parameters

$site_idintrequired
Site ID.
$keystringoptional
The meta key to retrieve. By default, returns data for all keys. Default empty.
$singlebooloptional
Whether to return a single value.
This parameter has no effect if $key is not specified.

Default:false

Return

mixed An array of values if $single is false.
The value of meta data field if $single is true.
False for an invalid $site_id (non-numeric, zero, or negative value).
An empty array if a valid but non-existing site ID is passed and $single is false.
An empty string if a valid but non-existing site ID is passed and $single is true.
Note: Non-serialized values are returned as strings:

  • false values are returned as empty strings ('')
  • true values are returned as '1'
  • numbers (both integer and float) are returned as strings Arrays and objects retain their original type.

Source

function get_site_meta( $site_id, $key = '', $single = false ) {
	return get_metadata( 'blog', $site_id, $key, $single );
}

Changelog

Version Description
5.1.0 Introduced.

User Contributed Notes