Changeset 11533
- Timestamp:
- 04/20/2017 12:56:53 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-functions.php
r11532 r11533 705 705 'type' => false, // Active, newest, alphabetical, random, popular, most-forum-topics or most-forum-posts. 706 706 'order' => 'DESC', // 'ASC' or 'DESC' 707 'orderby' => 'date_created', // date_created, last_activity, total_member_count, name, random .707 'orderby' => 'date_created', // date_created, last_activity, total_member_count, name, random, meta_id. 708 708 'user_id' => false, // Pass a user_id to limit to only groups that this user is a member of. 709 709 'include' => false, // Only include these specific groups (group_ids). -
trunk/src/bp-groups/classes/class-bp-groups-group.php
r11532 r11533 884 884 * Default: null. 885 885 * @type string $orderby Optional. Property to sort by. 'date_created', 'last_activity', 886 * 'total_member_count', 'name', 'random'. Default: 'date_created'. 886 * 'total_member_count', 'name', 'random', 'meta_id'. 887 * Default: 'date_created'. 887 888 * @type string $order Optional. Sort order. 'ASC' or 'DESC'. Default: 'DESC'. 888 889 * @type int $per_page Optional. Number of items to return per page of results. … … 994 995 $where_conditions = array(); 995 996 996 997 997 if ( ! empty( $r['status'] ) ) { 998 998 if ( ! is_array( $r['status'] ) ) { … … 1139 1139 $sql['from'] .= " JOIN {$bp->groups->table_name_groupmeta} gm_last_activity on ( g.id = gm_last_activity.group_id )"; 1140 1140 $where_conditions['last_activity'] = "gm_last_activity.meta_key = 'last_activity'"; 1141 } 1142 1143 // If 'meta_id' is the requested order, and there's no meta query, fall back to the default. 1144 if ( 'meta_id' === $orderby && empty( $meta_query_sql['join'] ) ) { 1145 $orderby = 'date_created'; 1141 1146 } 1142 1147 … … 1443 1448 $order_by_term = 'rand()'; 1444 1449 break; 1450 1451 case 'meta_id' : 1452 $order_by_term = buddypress()->groups->table_name_groupmeta . '.id'; 1453 break; 1445 1454 } 1446 1455 -
trunk/tests/phpunit/testcases/groups/class-bp-groups-group.php
r11532 r11533 957 957 } 958 958 959 /** 960 * @group groups_get_orderby_meta_id 961 */ 962 public function test_get_orderby_meta_id() { 963 $g1 = $this->factory->group->create(); 964 $g2 = $this->factory->group->create(); 965 $g3 = $this->factory->group->create(); 966 967 groups_update_groupmeta( $g2, 'orderup', 'sammy' ); 968 groups_update_groupmeta( $g1, 'orderup', 'sammy' ); 969 970 $args = array( 971 'meta_query' => array( 972 array( 973 'key' => 'orderup', 974 'value' => 'sammy' 975 ), 976 ), 977 'orderby' => 'meta_id', 978 'order' => 'ASC', 979 ); 980 $groups = BP_Groups_Group::get( $args ); 981 982 $found = wp_list_pluck( $groups['groups'], 'id' ); 983 $this->assertEquals( array( $g2, $g1 ), $found ); 984 } 985 986 /** 987 * @group groups_get_orderby_meta_id 988 */ 989 public function test_get_orderby_meta_id_invalid_fallback_to_date_created() { 990 $time = time(); 991 $g1 = $this->factory->group->create( array( 992 'date_created' => gmdate( 'Y-m-d H:i:s', $time - 10000 ), 993 ) ); 994 $g2 = $this->factory->group->create( array( 995 'date_created' => gmdate( 'Y-m-d H:i:s', $time - 1000 ), 996 ) ); 997 $g3 = $this->factory->group->create( array( 998 'date_created' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 999 ) ); 1000 1001 $args = array( 1002 'orderby' => 'meta_id', 1003 ); 1004 $groups = BP_Groups_Group::get( $args ); 1005 1006 // Orderby meta_id should be ignored if no meta query is present. 1007 $found = wp_list_pluck( $groups['groups'], 'id' ); 1008 $this->assertEquals( array( $g3, $g2, $g1 ), $found ); 1009 } 1010 959 1011 public function test_filter_user_groups_normal_search() { 960 1012 $g1 = $this->factory->group->create( array(
Note: See TracChangeset
for help on using the changeset viewer.