wp_set_post_tags()
wp_set_post_tags( int $post_id, string|array $tags = ”,…
wp_set_post_tags( int $post_id, string|array $tags = ”, bool $append = false )
为帖子设置标签。
Set the tags for a post.
目录锚点:#说明#参数#源码#笔记
说明(Description)
另请参阅wp_set_object_terms()
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $post_id | (int) | Post ID.不默认为全局$Post的ID。 |
| $tags | (string | array) | 为post设置的标记数组,或用逗号分隔的标记字符串。 |
| $append | (bool) | 如果为true,则不要删除现有标记,只需添加。如果为false,则将标记替换为新标记。 |
源码(Source)
/**
* Set the tags for a post.
*
* @since 2.3.0
*
* @see wp_set_object_terms()
*
* @param int $post_id Optional. The Post ID. Does not default to the ID of the global $post.
* @param string $tags Optional. The tags to set for the post, separated by commas.
* Default empty.
* @param bool $append Optional. If true, don't delete existing tags, just add on. If false,
* replace the tags with the new tags. Default false.
* @return array|false|WP_Error Array of affected term IDs. WP_Error or false on failure.
*/
function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) {
return wp_set_post_terms( $post_id, $tags, 'post_tag', $append);
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.3.0 | wp-includes/post.php | 7 | 14 |
笔记(Notes)
要在ID为42的帖子的当前标签之外添加标签“含义”和“生命”:
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!