Advertisements

wp_set_post_terms

Definition:
function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $append = false ) {}

Set the terms for a post.

Parameters

  • int $post_id: Post ID.
  • string $tags: The tags to set for the post, separated by commas.
  • bool $append: If true, don’t delete existing tags, just add on. If false, replace the tags with the new tags.
  • $taxonomy

Return values

returns:Array of affected term IDs. WP_Error or false on failure.

Source code

function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $append = false ) {

	$post_id = (int) $post_id;



	if ( !$post_id )

		return false;



	if ( empty($tags) )

		$tags = array();



	$tags = is_array($tags) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") );



	// Hierarchical taxonomies must always pass IDs rather than names so that children with the same

	// names but different parents aren't confused.

	if ( is_taxonomy_hierarchical( $taxonomy ) ) {

		$tags = array_map( 'intval', $tags );

		$tags = array_unique( $tags );

	}



	return wp_set_object_terms($post_id, $tags, $taxonomy, $append);

}

4119

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: