wp_set_link_cats() WordPress Function

The wp_set_link_cats() function is used to set the link category for a given link.

wp_set_link_cats( int $link_id, int[] $link_categories = array() ) #

Update link with the specified link categories.


Parameters

$link_id

(int)(Required)ID of the link to update.

$link_categories

(int[])(Optional)Array of link category IDs to add the link to.

Default value: array()


Top ↑

Source

File: wp-admin/includes/bookmark.php

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


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.