Skip to:
Content

BuddyPress.org

Ticket #4591: bp-groups-classes.diff

File bp-groups-classes.diff, 3.0 KB (added by DennisSmolek, 11 years ago)

First pass at a 1.7 patch to add group meta searching.

  • bp-groups-classes.php

     
    347347                $total_sql = array();
    348348
    349349                $sql['select'] = "SELECT g.*, gm1.meta_value AS total_member_count, gm2.meta_value AS last_activity";
    350                 $sql['from']   = " FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2,";
     350                $sql['from']   = " FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3";
    351351
    352352                if ( !empty( $user_id ) )
    353353                        $sql['members_from'] = " {$bp->groups->table_name_members} m,";
     
    357357                if ( !empty( $user_id ) )
    358358                        $sql['user_where'] = " g.id = m.group_id AND";
    359359
    360                 $sql['where'] = " g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'";
     360                $sql['where'] = " g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'";
    361361
    362362                if ( empty( $show_hidden ) )
    363363                        $sql['hidden'] = " AND g.status != 'hidden'";
    364364
    365365                if ( !empty( $search_terms ) ) {
    366366                        $search_terms = like_escape( $wpdb->escape( $search_terms ) );
    367                         $sql['search'] = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
     367                        $sql['search'] = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' OR gm3.meta_value LIKE '%%{$search_terms}%%' )";
    368368                }
    369369
    370370                if ( !empty( $user_id ) )
     
    411411                $paged_groups_sql = apply_filters( 'bp_groups_get_paged_groups_sql', join( ' ', (array) $sql ), $sql );
    412412                $paged_groups     = $wpdb->get_results( $paged_groups_sql );
    413413
    414                 $total_sql['select'] = "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name} g, {$bp->groups->table_name_members} gm1, {$bp->groups->table_name_groupmeta} gm2";
     414                $total_sql['select'] = "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name} g, {$bp->groups->table_name_members} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3";
    415415
    416416                if ( !empty( $user_id ) )
    417417                        $total_sql['select'] .= ", {$bp->groups->table_name_members} m";
     
    420420                        $total_sql['where'][] = "g.status != 'hidden'";
    421421
    422422                if ( !empty( $sql['search'] ) )
    423                         $total_sql['where'][] = "( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
     423                        $total_sql['where'][] = "( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' OR gm3.meta_value LIKE '%%{$search_terms}%%')";
    424424
    425425                if ( !empty( $user_id ) )
    426426                        $total_sql['where'][] = "m.group_id = g.id AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0";
     
    435435
    436436                $total_sql['where'][] = "g.id = gm1.group_id";
    437437                $total_sql['where'][] = "g.id = gm2.group_id";
     438                $total_sql['where'][] = "g.id = gm3.group_id";
    438439                $total_sql['where'][] = "gm2.meta_key = 'last_activity'";
    439440
    440441                $t_sql = $total_sql['select'];