bbp_admin_repair_topic_meta

Recaches the topic for each post.

Description

(array) bbp_admin_repair_topic_meta(); 

Returns (array)

An array of the status code and the message


Usage

  1. if ( !function_exists( 'bbp_admin_repair_topic_meta' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/admin/tools.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bbp_admin_repair_topic_meta(); 
  7.  

Defined (1)

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

/includes/admin/tools.php  
  1. function bbp_admin_repair_topic_meta() { 
  2. global $wpdb; 
  3.  
  4. $statement = __( 'Recalculating the topic for each post … %s', bbpress ); 
  5. $result = __( 'Failed!', bbpress ); 
  6.  
  7. // First, delete everything. 
  8. if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_topic_id';" ) ) ) 
  9. return array( 1, sprintf( $statement, $result ) ); 
  10.  
  11. // Next, give all the topics with replies the ID their last reply. 
  12. if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) 
  13. ( SELECT `topic`.`ID`, '_bbp_topic_id', `topic`.`ID` 
  14. FROM `$wpdb->posts` 
  15. AS `topic` 
  16. WHERE `topic`.`post_type` = 'topic' 
  17. GROUP BY `topic`.`ID` );" ) ) ) 
  18. return array( 3, sprintf( $statement, $result ) ); 
  19.  
  20. // Next, give all the topics with replies the ID their last reply. 
  21. if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) 
  22. ( SELECT `reply`.`ID`, '_bbp_topic_id', `topic`.`ID` 
  23. FROM `$wpdb->posts` 
  24. AS `reply` 
  25. INNER JOIN `$wpdb->posts` 
  26. AS `topic` 
  27. ON `reply`.`post_parent` = `topic`.`ID` 
  28. WHERE `topic`.`post_type` = 'topic' 
  29. AND `reply`.`post_type` = 'reply' 
  30. GROUP BY `reply`.`ID` );" ) ) ) 
  31. return array( 4, sprintf( $statement, $result ) ); 
  32.  
  33. // Complete results 
  34. return array( 0, sprintf( $statement, __( 'Complete!', bbpress ) ) );