diff --git src/bp-groups/bp-groups-classes.php src/bp-groups/bp-groups-classes.php
index 6924794..8ec0d90 100644
|
|
class BP_Groups_Group { |
893 | 893 | if ( ! empty( $matches_a[1] ) && ! empty( $matches_b[1] ) ) { |
894 | 894 | $sql_array['join'] = implode( ',', $matches_a[1] ). ', '; |
895 | 895 | |
896 | | $sql_array['where'] = ''; |
897 | | |
898 | | $meta_query_where_clauses = explode( "\n", $meta_sql['where'] ); |
899 | | |
900 | | // Trim empties |
901 | | $meta_query_where_clauses = array_values( array_filter( $meta_query_where_clauses ) ); |
902 | | |
903 | | foreach( $matches_b[1] as $key => $group_id_clause ) { |
904 | | $sql_array['where'] .= ' ' . preg_replace( '/^(AND\s+[\(\s]+)/', '$1' . $group_id_clause . ' AND ', ltrim( $meta_query_where_clauses[ $key ] ) ); |
905 | | } |
906 | | |
| 896 | $sql_array['where'] = $meta_sql['where'] . ' AND ' . implode( ' AND ', $matches_b[1] ); |
907 | 897 | } |
908 | 898 | } |
909 | 899 | |
… |
… |
class BP_Groups_Member_Suggestions extends BP_Members_Suggestions { |
4489 | 4479 | |
4490 | 4480 | return apply_filters( 'bp_groups_member_suggestions_get_suggestions', $results, $this ); |
4491 | 4481 | } |
4492 | | } |
4493 | | No newline at end of file |
| 4482 | } |
diff --git tests/phpunit/testcases/groups/class-bp-groups-group.php tests/phpunit/testcases/groups/class-bp-groups-group.php
index 826fa83..2b77772 100644
|
|
class BP_Tests_BP_Groups_Group_TestCases extends BP_UnitTestCase { |
136 | 136 | |
137 | 137 | /** |
138 | 138 | * @group get |
| 139 | * @group group_meta_query |
| 140 | * @ticket BP5824 |
| 141 | */ |
| 142 | public function test_get_with_meta_query_multiple_keys_with_same_value() { |
| 143 | $now = time(); |
| 144 | $g1 = $this->factory->group->create( array( |
| 145 | 'last_activity' => date( 'Y-m-d H:i:s', $now - 60*60 ), |
| 146 | ) ); |
| 147 | $g2 = $this->factory->group->create( array( |
| 148 | 'last_activity' => date( 'Y-m-d H:i:s', $now - 60*60*2 ), |
| 149 | ) ); |
| 150 | groups_update_groupmeta( $g1, 'foo', 'bar' ); |
| 151 | groups_update_groupmeta( $g2, 'foo', 'b' ); |
| 152 | groups_update_groupmeta( $g2, 'foo2', 'bar' ); |
| 153 | |
| 154 | $groups = BP_Groups_Group::get( array( |
| 155 | 'meta_query' => array( |
| 156 | 'relation' => 'AND', |
| 157 | array( |
| 158 | 'key' => 'foo', |
| 159 | 'value' => 'bar', |
| 160 | 'compare' => '=' |
| 161 | ), |
| 162 | ), |
| 163 | ) ); |
| 164 | $ids = wp_list_pluck( $groups['groups'], 'id' ); |
| 165 | $this->assertEquals( $ids, array( $g1 ) ); |
| 166 | $this->assertEquals( 1, $groups['total'] ); |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * @group get |
139 | 171 | */ |
140 | 172 | public function test_get_normal_search() { |
141 | 173 | $g1 = $this->factory->group->create( array( |