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

wp_set_post_lock

Definition:
function wp_set_post_lock( $post_id ) {}

Mark the post as currently being edited by the current user

Parameters

  • int $post_id: ID of the post to being edited

Return values

returns:Returns false if the post doesn’t exist of there is no current user, or an array of the lock time and the user ID.

Source code

function wp_set_post_lock( $post_id ) {

	if ( !$post = get_post( $post_id ) )

		return false;

	if ( 0 == ($user_id = get_current_user_id()) )

		return false;



	$now = time();

	$lock = "$now:$user_id";



	update_post_meta( $post->ID, '_edit_lock', $lock );

}

4115

wp_set_post_cats

Definition:
function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array() {}

Sets the categories that the post id belongs to.

Parameters

  • int $blogid: Not used
  • int $post_ID
  • array $post_categories

Source code

function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) {

	_deprecated_function( __FUNCTION__, '2.1', 'wp_set_post_categories()' );

	return wp_set_post_categories($post_ID, $post_categories);

}

4113

wp_set_post_categories

Definition:
function wp_set_post_categories($post_ID = 0, $post_categories = array() {}

Set categories for a post.
If the post categories parameter is not set, then the default category is going used.

Parameters

  • int $post_ID: Post ID.
  • array $post_categories: Optional. List of categories.

Source code

function wp_set_post_categories($post_ID = 0, $post_categories = array()) {

	$post_ID = (int) $post_ID;

	$post_type = get_post_type( $post_ID );

	$post_status = get_post_status( $post_ID );

	// If $post_categories isn't already an array, make it one:

	if ( !is_array($post_categories) || empty($post_categories) ) {

		if ( 'post' == $post_type && 'auto-draft' != $post_status )

			$post_categories = array( get_option('default_category') );

		else

			$post_categories = array();

	} else if ( 1 == count($post_categories) && '' == reset($post_categories) ) {

		return true;

	}



	if ( !empty($post_categories) ) {

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

		$post_categories = array_unique($post_categories);

	}



	return wp_set_object_terms($post_ID, $post_categories, 'category');

}

4111