bbp_get_reply_position_raw( int $reply_id, int $topic_id )
Get the position of a reply by querying the DB directly for the replies of a given topic.
Description
Parameters
- $reply_id
-
(Required)
- $topic_id
-
(Required)
Source
File: bp-forums/replies/functions.php
function bbp_get_reply_position_raw( $reply_id = 0, $topic_id = 0 ) {
// Get required data
$reply_id = bbp_get_reply_id( $reply_id );
$topic_id = !empty( $topic_id ) ? bbp_get_topic_id( $topic_id ) : bbp_get_reply_topic_id( $reply_id );
$reply_position = 0;
// If reply is actually the first post in a topic, return 0
if ( $reply_id !== $topic_id ) {
// Make sure the topic has replies before running another query
$reply_count = bbp_get_topic_reply_count( $topic_id, false );
if ( !empty( $reply_count ) ) {
// Get reply id's
$topic_replies = bbp_get_all_child_ids( $topic_id, bbp_get_reply_post_type() );
if ( !empty( $topic_replies ) ) {
// Reverse replies array and search for current reply position
$topic_replies = array_reverse( $topic_replies );
$reply_position = array_search( (string) $reply_id, $topic_replies );
// Bump the position to compensate for the lead topic post
$reply_position++;
}
}
}
return (int) $reply_position;
}
Changelog
| Version | Description |
|---|---|
| bbPress (r3933) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.