钩子文档

default_{$meta_type}_metadata

💡 云策文档标注

概述

default_{$meta_type}_metadata 是一个 WordPress 过滤器钩子,用于过滤指定元键和对象的默认元数据值。它允许开发者在获取元数据时自定义默认返回值,适用于博客、文章、评论、术语、用户等多种对象类型。

关键要点

  • 钩子名称是动态的,基于 $meta_type 参数,例如 default_post_metadata 或 default_user_metadata。
  • 参数包括 $value(返回值)、$object_id(对象ID)、$meta_key(元键)、$single(是否返回单个值)和 $meta_type(对象类型)。
  • 主要用于 get_metadata_default() 函数中,在 WordPress 5.5.0 版本引入。

代码示例

$value = apply_filters( "default_{$meta_type}_metadata", $value, $object_id, $meta_key, $single, $meta_type );

📄 原文内容

Filters the default metadata value for a specified meta key and object.

Description

The dynamic portion of the hook name, $meta_type, refers to the meta object type (blog, post, comment, term, user, or any other type with an associated meta table).

Possible filter names include:

  • default_blog_metadata
  • default_post_metadata
  • default_comment_metadata
  • default_term_metadata
  • default_user_metadata

Parameters

$valuemixed
The value to return, either a single metadata value or an array of values depending on the value of $single.
$object_idint
ID of the object metadata is for.
$meta_keystring
Metadata key.
$singlebool
Whether to return only the first value of the specified $meta_key.
$meta_typestring
Type of object metadata is for. Accepts 'blog', 'post', 'comment', 'term', 'user', or any other object type with an associated meta table.

Source

$value = apply_filters( "default_{$meta_type}_metadata", $value, $object_id, $meta_key, $single, $meta_type );

Changelog

Version Description
5.5.0 Introduced.