bbp_forum_query_last_reply_id( int $forum_id, int $topic_ids )

Returns the forum’s last reply id

Description

Parameters

$forum_id

(Required) Forum id

$topic_ids

(Optional) Topic ids

Source

File: bp-forums/forums/functions.php

2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
function bbp_forum_query_last_reply_id( $forum_id, $topic_ids = 0 ) {
    global $wpdb;
 
    $cache_id = 'bbp_get_forum_' . $forum_id . '_reply_id';
    $reply_id = wp_cache_get( $cache_id, 'bbpress_posts' );
 
    if ( false === $reply_id ) {
 
        if ( empty( $topic_ids ) ) {
            $topic_ids = bbp_forum_query_topic_ids( $forum_id );
        }
 
        if ( !empty( $topic_ids ) ) {
            $topic_ids = implode( ',', wp_parse_id_list( $topic_ids ) );
            $reply_id  = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );
            wp_cache_set( $cache_id, $reply_id, 'bbpress_posts' ); // May be (int) 0
        } else {
            wp_cache_set( $cache_id, '0', 'bbpress_posts' );
        }
    }
 
    return (int) apply_filters( 'bbp_get_forum_last_reply_id', (int) $reply_id, $forum_id );
}

Changelog

Changelog
Version Description
bbPress (r2908) 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.