wp_add_post_tags()
云策文档标注
概述
wp_add_post_tags() 函数用于向文章添加标签,是 wp_set_post_tags() 的包装函数,通过设置追加模式实现标签添加而非替换。
关键要点
- 函数接受两个参数:$post_id(文章ID,可选,默认为0)和 $tags(标签字符串或数组,可选,默认为空)。
- 返回值为受影响的术语ID数组,失败时返回 false 或 WP_Error。
- 内部调用 wp_set_post_tags() 并设置追加标志为 true,确保新标签被添加到现有标签中。
- 函数自 WordPress 2.3.0 版本引入,相关函数包括 wp_set_post_tags()。
原文内容
Adds tags to a post.
Description
See also
Parameters
$post_idintoptional-
The Post ID. Does not default to the ID of the global $post.
$tagsstring|arrayoptional-
An array of tags to set for the post, or a string of tags separated by commas. Default empty.
Source
function wp_add_post_tags( $post_id = 0, $tags = '' ) {
return wp_set_post_tags( $post_id, $tags, true );
}
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |
Skip to note 2 content
Monzur Alam
For single tag insert,
For multiple tag insert,