Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/22/2011 12:40:24 PM (14 years ago)
Author:
boonebgorges
Message:

Ensure that total forum count is correct when a search term is passed to the topic loop

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-classes.php

    r4770 r4787  
    607607     * @return int The topic count
    608608     */
    609     function get_global_topic_count( $status = 'public' ) {
     609    function get_global_topic_count( $status = 'public', $search_terms = false ) {
    610610        global $bbdb, $wpdb, $bp;
    611611       
     
    629629        }
    630630       
    631         return $wpdb->get_var( "SELECT COUNT(t.topic_id) FROM {$bbdb->topics} AS t INNER JOIN {$bp->groups->table_name_groupmeta} AS gm ON t.forum_id = gm.meta_value INNER JOIN {$bp->groups->table_name} AS g ON gm.group_id = g.id WHERE gm.meta_key = 'forum_id' {$status_sql} AND t.topic_status = '0' AND t.topic_sticky != '2' " );
     631        $sql = array();
     632       
     633        $sql['select'] = "SELECT COUNT(t.topic_id)";
     634       
     635        $sql['from'] = "FROM {$bbdb->topics} AS t INNER JOIN {$bp->groups->table_name_groupmeta} AS gm ON t.forum_id = gm.meta_value INNER JOIN {$bp->groups->table_name} AS g ON gm.group_id = g.id";
     636       
     637        $sql['where'] = "WHERE gm.meta_key = 'forum_id' {$status_sql} AND t.topic_status = '0' AND t.topic_sticky != '2'";
     638       
     639        if ( $search_terms ) {
     640            $st = like_escape( $search_terms );
     641            $sql['where'] .= " AND (  t.topic_title LIKE '%{$st}%' )";
     642        }
     643       
     644        return $wpdb->get_var( implode( ' ', $sql ) );
    632645    }
    633646}
Note: See TracChangeset for help on using the changeset viewer.