wp_set_link_cats

Update link with the specified link categories.

Description

wp_set_link_cats( (int) $link_id = 0, (array) $link_categories = array() ); 

Parameters (2)

0. $link_id — Optional. (int)
ID of the link to update.
1. $link_categories — Optional. (array) => array()
Array of link categories to add the link to.

Usage

  1. if ( !function_exists( 'wp_set_link_cats' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/bookmark.php'; 
  3.  
  4. // ID of the link to update. 
  5. $link_id = -1; 
  6.  
  7. // Array of link categories to add the link to. 
  8. $link_categories = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_set_link_cats($link_id, $link_categories); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/bookmark.php  
  1. function wp_set_link_cats( $link_id = 0, $link_categories = array() ) { 
  2. // If $link_categories isn't already an array, make it one: 
  3. if ( !is_array( $link_categories ) || 0 == count( $link_categories ) ) 
  4. $link_categories = array( get_option( 'default_link_category' ) ); 
  5.  
  6. $link_categories = array_map( 'intval', $link_categories ); 
  7. $link_categories = array_unique( $link_categories ); 
  8.  
  9. wp_set_object_terms( $link_id, $link_categories, 'link_category' ); 
  10.  
  11. clean_bookmark_cache( $link_id );