Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/20/2017 12:56:53 AM (9 years ago)
Author:
dcavins
Message:

Add 'meta_id' orderby option to BP_Groups_Group::get().

Add meta_id orderby option to groups_get_groups() and its
underlying function BP_Groups_Group::get(). When searching for groups
by meta value, the found groups may now be ordered by the order in
which the found meta rows appear in the bp_groups_groupmeta table.

See #6014.

File:
1 edited

Legend:

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

    r11532 r11533  
    884884     *                                            Default: null.
    885885     *     @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'.
    887888     *     @type string       $order              Optional. Sort order. 'ASC' or 'DESC'. Default: 'DESC'.
    888889     *     @type int          $per_page           Optional. Number of items to return per page of results.
     
    994995        $where_conditions = array();
    995996
    996 
    997997        if ( ! empty( $r['status'] ) ) {
    998998            if ( ! is_array( $r['status'] ) ) {
     
    11391139            $sql['from'] .= " JOIN {$bp->groups->table_name_groupmeta} gm_last_activity on ( g.id = gm_last_activity.group_id )";
    11401140            $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';
    11411146        }
    11421147
     
    14431448                $order_by_term = 'rand()';
    14441449                break;
     1450
     1451            case 'meta_id' :
     1452                $order_by_term = buddypress()->groups->table_name_groupmeta . '.id';
     1453                break;
    14451454        }
    14461455
Note: See TracChangeset for help on using the changeset viewer.