bb_update_post_positions

The BuddyPress bb update post positions function.

Description

bb_update_post_positions( $topic_id ); 

Parameters (1)

0. $topic_id
The topic id.

Usage

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

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-posts.php  
  1. function bb_update_post_positions( $topic_id ) { 
  2. global $bbdb; 
  3. $topic_id = (int) $topic_id; 
  4. $posts = get_thread( $topic_id, array( 'per_page' => '-1' ) ); 
  5. if ( $posts ) { 
  6. foreach ( $posts as $i => $post ) { 
  7. $bbdb->query( $bbdb->prepare( "UPDATE $bbdb->posts SET post_position = %d WHERE post_id = %d", $i + 1, $post->post_id ) ); 
  8. wp_cache_delete( (int) $post->post_id, 'bb_post' ); 
  9. wp_cache_delete( $topic_id, 'bb_thread' ); 
  10. wp_cache_flush( bb_query ); 
  11. wp_cache_flush( 'bb_cache_posts_post_ids' ); 
  12. return true; 
  13. } else { 
  14. return false;