Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to count sent messages


  • Horoshiy
    Participant

    @horoshiy

    Good day.

    I’d like to count messages in sentbox. I’m using function:


    function get_total_threads_for_user( $user_id, $box = 'inbox', $type = 'all' ) {
    global $wpdb, $bp;

    $exclude_sender = '';
    if ( $box != 'sentbox' )
    $exclude_sender = ' AND sender_only != 1';

    if ( $type == 'unread' )
    $type_sql = $wpdb->prepare( " AND unread_count != 0 " );
    else if ( $type == 'read' )
    $type_sql = $wpdb->prepare( " AND unread_count = 0 " );

    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 ) );
    }

    i’m counting this way: get_total_threads_for_user( bp_loggedin_user_id(), ‘sentbox’, ‘all’ );
    and it returns wrong results. I have no messages in my sentbox, but i have 1 message in inbox and function returns “1”.
    my assumption is that this function counts all messages in case $box = ‘sentbox’

    Any ideas what’s happening and how to correct this?

    And one more question. There is a field ‘sender_only’ in table `wp_bp_messages_recipients`. What’s the purpose of this field?

    Thanks in advance,
    Dmitriy.

  • The topic ‘How to count sent messages’ is closed to new replies.
Skip to toolbar