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
2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 | 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.