bb_remove_topic_tags

Bb_remove_topic_tag() - Removes all bb_topic_tags from a topic.

Description

bb_remove_topic_tags( (int) $topic_id ); 

Parameters (1)

0. $topic_id (int)
The topic id.

Usage

  1. if ( !function_exists( 'bb_remove_topic_tags' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-topic-tags.php'; 
  3.  
  4. // The topic id. 
  5. $topic_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bb_remove_topic_tags($topic_id); 
  9.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-topic-tags.php  
  1. function bb_remove_topic_tags( $topic_id ) { 
  2. global $wp_taxonomy_object; 
  3. $topic_id = (int) $topic_id; 
  4. if ( !$topic_id || !get_topic( $topic_id ) ) 
  5. return false; 
  6.  
  7. $_tags = bb_get_topic_tags( $topic_id ); 
  8.  
  9.  
  10. $wp_taxonomy_object->delete_object_term_relationships( $topic_id, 'bb_topic_tag' ); 
  11.  
  12. global $bbdb; 
  13. $bbdb->query( $bbdb->prepare( 
  14. "UPDATE $bbdb->topics SET tag_count = 0 WHERE topic_id = %d", $topic_id 
  15. ) ); 
  16. wp_cache_delete( $topic_id, 'bb_topic' ); 
  17.  
  18. if ( $_tags ) { 
  19. foreach ( $_tags as $_tag ) { 
  20. // Count is updated at delete_object_term_relationships() 
  21. if ( 2 > $_tag->tag_count ) { 
  22. bb_destroy_tag( $_tag->term_taxonomy_id ); 
  23.  
  24. return true;