wp_set_link_cats

函数


wp_set_link_cats ( $link_id = 0, $link_categories = array() )
参数
  • (int)
    $link_id
    ID of the link to update.
    Required:
  • (int[])
    $link_categories
    Array of link category IDs to add the link to.
    Required:
    Default: array()
定义位置
  • wp-admin/includes/bookmark.php
    , line 278
引入
2.1.0
弃用

Update link with the specified link categories.

function wp_set_link_cats( $link_id = 0, $link_categories = array() ) {
	// If $link_categories isn't already an array, make it one:
	if ( ! is_array( $link_categories ) || 0 === count( $link_categories ) ) {
		$link_categories = array( get_option( 'default_link_category' ) );
	}

	$link_categories = array_map( 'intval', $link_categories );
	$link_categories = array_unique( $link_categories );

	wp_set_object_terms( $link_id, $link_categories, 'link_category' );

	clean_bookmark_cache( $link_id );
}