目录
描述
Set tags for a post. Every tag that does not already exist will be automatically created. Uses wp_set_post_terms().
用法
<?php wp_set_post_tags( $post_ID, $tags, $append ) ?>
参数
$post_ID
(integer) (必填) Post ID.
默认值: 0
$tags
(string,array) (可选) List of tags. Can be an array or a comma separated string.
默认值: array
$append
(boolean) (可选) If true, tags will be appended to the post. If false, tags will replace existing tags.
默认值: false
返回值
(boolean|null)
Will return false if $post_id is not an integer or is 0. Will return null otherwise.
示例
To add the tags meaning and life to the current tags of the post with ID 42:
1 2 3 4 5 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ wp_set_post_tags( 42, 'meaning,life', true ); |
历史
添加于 版本: 2.3.0
源文件
wp_set_post_tags() 函数的代码位于 wp-includes/post.php
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ /** * 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); } |
- 原文:http://codex.wordpress.org/Function_Reference/wp_set_post_tags
- 翻译:黄聪@WordPress之魂