描述:

使用代码设置一篇文章的标签Tags信息

用法:

<?php wp_set_post_tags( $post_ID, $tags, $append ) ?>

参数:

$post_ID

(integer) (必填) 文章ID

默认值: 0

$tags

(string,array) (可选) 标签

默认值: array

$append

(boolean) (可选) 如果为true,则标记将附加到帖子中。如果为false,标签将替换现有的标签。

默认值: false

示例:

wp_set_post_tags( 42, 'meaning,life', true );

源文件:

/**
 * 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);
}

 

参与评论