_get_meta_table()
云策文档标注
概述
_get_meta_table() 函数用于获取指定对象类型的元数据表名,支持多种 WordPress 对象类型,如 'blog'、'post'、'comment'、'term'、'user' 等。如果对应的元数据表不存在,则返回 false。
关键要点
- 参数 $type 为字符串类型,必需,指定对象类型,例如 'post' 或 'user'。
- 返回值是字符串(元数据表名)或 false(如果表不存在)。
- 函数内部通过全局变量 $wpdb 访问数据库表名,基于 $type 拼接 'meta' 后缀来构建表名。
代码示例
function _get_meta_table( $type ) {
global $wpdb;
$table_name = $type . 'meta';
if ( empty( $wpdb->$table_name ) ) {
return false;
}
return $wpdb->$table_name;
}
原文内容
Retrieves the name of the metadata table for the specified object type.
Parameters
$typestringrequired-
Type of object metadata is for. Accepts
'blog','post','comment','term','user', or any other object type with an associated meta table.
Source
function _get_meta_table( $type ) {
global $wpdb;
$table_name = $type . 'meta';
if ( empty( $wpdb->$table_name ) ) {
return false;
}
return $wpdb->$table_name;
}
Changelog
| Version | Description |
|---|---|
| 2.9.0 | Introduced. |