bbp_update_reply_position

Update the position of the reply.

Description

bbp_update_reply_position( (int) $reply_id = 0, (int) $reply_position = 0 ); 

The reply position is stored in the menu_order column of the posts table. This is done to prevent using a meta_query to retrieve posts in the proper freshness order. By updating the menu_order accordingly, we're able to leverage core WordPress query ordering much more effectively.

Parameters (2)

0. $reply_id — Optional. (int)
The reply id.
1. $reply_position — Optional. (int)
The reply position.

Usage

  1. if ( !function_exists( 'bbp_update_reply_position' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/replies/functions.php'; 
  3.  
  4. // The reply id. 
  5. $reply_id = -1; 
  6.  
  7. // The reply position. 
  8. $reply_position = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_update_reply_position($reply_id, $reply_position); 
  12.  

Defined (1)

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

/includes/replies/functions.php  
  1. function bbp_update_reply_position( $reply_id = 0, $reply_position = 0 ) { 
  2.  
  3. // Bail if reply_id is empty 
  4. $reply_id = bbp_get_reply_id( $reply_id ); 
  5. if ( empty( $reply_id ) ) 
  6. return false; 
  7.  
  8. // If no position was passed, get it from the db and update the menu_order 
  9. if ( empty( $reply_position ) ) { 
  10. $reply_position = bbp_get_reply_position_raw( $reply_id, bbp_get_reply_topic_id( $reply_id ) ); 
  11.  
  12. // Update the replies' 'menp_order' with the reply position 
  13. wp_update_post( array( 
  14. 'ID' => $reply_id,  
  15. 'menu_order' => $reply_position 
  16. ) ); 
  17.  
  18. return (int) $reply_position;