Skip to:
Content

BuddyPress.org

Changeset 4787


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

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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-forums/bp-forums-template.php

    r4786 r4787  
    143143                                // For forum directories, get a true count
    144144                                $status = is_super_admin() ? 'all' : 'public'; // todo: member-of
    145                                 $topic_count = (int)groups_total_forum_topic_count( $status );
     145                                $topic_count = (int)groups_total_forum_topic_count( $status, $search_terms );
    146146                        }
    147147
  • 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}
  • trunk/bp-groups/bp-groups-forums.php

    r4764 r4787  
    258258 * @return int The topic count
    259259 */
    260 function groups_total_forum_topic_count( $status = 'public' ) {
    261         return apply_filters( 'groups_total_forum_topic_count', BP_Groups_Group::get_global_topic_count( $status ) );
     260function groups_total_forum_topic_count( $status = 'public', $search_terms = false ) {
     261        return apply_filters( 'groups_total_forum_topic_count', BP_Groups_Group::get_global_topic_count( $status, $search_terms ) );
    262262}
    263263
Note: See TracChangeset for help on using the changeset viewer.