post_{$field}
云策文档标注
概述
本文档介绍 WordPress 中的 post_{$field} 过滤器,用于在显示时过滤特定文章字段的值。该过滤器仅适用于不以 post_ 为前缀的文章字段名。
关键要点
- 过滤器名称是动态的,基于字段名,例如 post_ID、post_comment_status 等。
- 参数包括字段值、文章 ID 和上下文(如 'display'、'edit' 等),用于控制字段的清理方式。
- 通过 apply_filters 调用,允许开发者修改字段值以适配不同显示场景。
代码示例
$value = apply_filters( "post_{$field}", $value, $post_id, $context );注意事项
- 仅适用于非 post_ 前缀的字段,如 ID、comment_status 等。
- 上下文参数影响 sanitize_post_field() 的行为,确保字段值在不同场景下安全输出。
原文内容
Filters the value of a specific post field for display.
Description
Only applied to post fields name which is not prefixed with post_.
The dynamic portion of the hook name, $field, refers to the post field name. Possible filter names include:
post_IDpost_comment_statuspost_ping_statuspost_to_pingpost_pingedpost_guidpost_menu_orderpost_comment_count
Parameters
$valuemixed-
Value of the unprefixed post field.
$post_idint-
Post ID
$contextstring-
Context for how to sanitize the field.
Accepts'raw','edit','db','display','attribute', or'js'. Default'display'.
Source
$value = apply_filters( "post_{$field}", $value, $post_id, $context );
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |