bbp_get_reply_position

Return the numeric position of a reply within a topic.

Description

(int) bbp_get_reply_position( (int) $reply_id = 0, (int) $topic_id = 0 ); 

Returns (int)

Reply position

Parameters (2)

0. $reply_id — Optional. (int)
Reply id
1. $topic_id — Optional. (int)
Topic id

Usage

  1. if ( !function_exists( 'bbp_get_reply_position' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/replies/template.php'; 
  3.  
  4. // Optional. Reply id 
  5. $reply_id = -1; 
  6.  
  7. // Optional. Topic id 
  8. $topic_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_get_reply_position($reply_id, $topic_id); 
  12.  

Defined (1)

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

/includes/replies/template.php  
  1. function bbp_get_reply_position( $reply_id = 0, $topic_id = 0 ) { 
  2.  
  3. // Get required data 
  4. $reply_id = bbp_get_reply_id( $reply_id ); 
  5. $reply_position = get_post_field( 'menu_order', $reply_id ); 
  6.  
  7. // Reply doesn't have a position so get the raw value 
  8. if ( empty( $reply_position ) ) { 
  9. $topic_id = !empty( $topic_id ) ? bbp_get_topic_id( $topic_id ) : bbp_get_reply_topic_id( $reply_id ); 
  10.  
  11. // Post is not the topic 
  12. if ( $reply_id !== $topic_id ) { 
  13. $reply_position = bbp_get_reply_position_raw( $reply_id, $topic_id ); 
  14.  
  15. // Update the reply position in the posts table so we'll never have 
  16. // to hit the DB again. 
  17. if ( !empty( $reply_position ) ) { 
  18. bbp_update_reply_position( $reply_id, $reply_position ); 
  19.  
  20. // Topic's position is always 0 
  21. } else { 
  22. $reply_position = 0; 
  23.  
  24. // Bump the position by one if the lead topic is in the replies loop 
  25. if ( ! bbp_show_lead_topic() ) 
  26. $reply_position++; 
  27.  
  28. return (int) apply_filters( 'bbp_get_reply_position', $reply_position, $reply_id, $topic_id );