MetaUtil
MetaUtil class provides helper methods for accessing and evaluating metadata across all WordPress meta tables.
Description
- Wraps access to the
Meta
class for post, user, term, comment, site, and blog metadata. - Supports protected key detection via
isProtected()
. - Resolves object subtypes (e.g., post type, taxonomy) using utility classes.
- Follows WordPress conventions from
meta.php
.
Usage
const context = await Application.getContext();
const metaUtil = context.components.get(MetaUtil);
const meta = await metaUtil.getValue("post", revisionId, "meta_key");
Methods
get
get(table: types.MetaTable, id: number): Meta
Returns a Meta
instance for the given table and object ID.
getValue
getValue<T = string>(
table: types.MetaTable,
id: number,
key: string
): Promise<T | undefined>
Fetches a single metadata value for the given key and object.
isProtected
isProtected(metaKey: string, metaType?: types.MetaTable): boolean
Returns true
if the key is considered protected (begins with _
).
getObjectSubtype
getObjectSubtype(
type: "post" | "comment" | "term" | "user",
id: number
): Promise<string>
Resolves the object subtype based on the type and ID:
post
: returns post type.term
: returns taxonomy.comment
: returns"comment"
if comment exists.user
: returns"user"
if user exists.