BP_Messages_Thread::get_total_threads_for_user( int $user_id, string $box = 'inbox', string $type = 'all' )

Returns the total number of message threads for a user.

Description

Parameters

$user_id

(Required) The user ID.

$box

(Optional) The type of mailbox to get. Either 'inbox' or 'sentbox'. Defaults to 'inbox'.

Default value: 'inbox'

$type

(Optional) The type of messages to get. Either 'all' or 'unread'. or 'read'. Defaults to 'all'.

Default value: 'all'

Return

(int) $value Total thread count for the provided user.

Source

File: bp-messages/classes/class-bp-messages-thread.php

1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
public static function get_total_threads_for_user( $user_id, $box = 'inbox', $type = 'all' ) {
    global $wpdb;
 
    $exclude_sender = $type_sql = '';
    // $exclude_sender = 'AND sender_only != 1';
 
    if ( $type === 'unread' ) {
        $type_sql = 'AND unread_count != 0';
    } elseif ( $type === 'read' ) {
        $type_sql = 'AND unread_count = 0';
    }
 
    $bp = buddypress();
 
    return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(thread_id) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0 {$exclude_sender} {$type_sql}", $user_id ) );
}

Changelog

Changelog
Version Description
BuddyPress 1.0.0 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.