WordPress 函数:sanitize_post_field()(过滤文章字段)
sanitize_post_field() 函数用来过滤文章信息的内容。
用法
sanitize_post_field( $field, $value, $post_id, $context );
参数
$field
(字符串)(必须)文章对象字段名。
默认值:None
$value
(混合)(必须)字段内容。
默认值:None
$post_id
(整数)(必须)文章 ID.
默认值:None
$context
(字符串)(必须)过滤的方法。可以是:raw、edit、db、display、attribute 和 js.
默认值:None
返回值
(混合)过滤后的值。
例子
过滤文章标题然后打印输出:
$post = get_post( 35 );
$post_title = sanitize_post_field( "post_title", $post->post_title, $post->ID, "display" );
echo $post_title;
过滤文章标题然后当做 Html 属性值输出:
$post = get_post( 543 );
$post_title = sanitize_post_field( "post_title", $post->post_title, $post->ID, "attribute" );
echo "<input type="hidden" name="post-title" value="" . $post_title . "" />";
其它
此函数位于:wp-includes/post.php