Order by custom field in member loop
-
Hi!
First of all thanks for the amazing work you are doing..
In my buddypress installation I’ve a rating associated to each member (each member can rate each other) and I would like to add “rating” to the “order by” option of the member page.Now I can do it with a widget that orders members with the function I report below. But I would like to add the possibility to order members by rating in the “order by” option.
I’ve seen the topic https://buddypress.org/support/topic/adding-new-order-by-on-members-loop/ trying to adapt it to my case, but the order by rating option do not work properly.
It is possible to adapt that solution (or another working) to my case?
Thanks in advance.function prorevs_users_by_rating($limit) { global $wpdb; if (current_user_can('administrator')): $users = $wpdb->get_results( $wpdb->prepare( "SELECT a.ID as id, a.user_login AS name, a.display_name AS displayname, AVG(star) AS rating, COUNT(star) AS reviews FROM {$wpdb->prefix}users AS a LEFT JOIN {$wpdb->prefix}bp_activity AS b ON a.ID = b.usercheck WHERE (b.is_activated is null or b.is_activated=1) GROUP BY id ORDER BY rating DESC LIMIT %d", $limit ) ); else: $users = $wpdb->get_results( $wpdb->prepare( "SELECT a.ID as id, a.user_login AS name, a.display_name AS displayname, AVG(star) AS rating, COUNT(star) AS reviews FROM {$wpdb->prefix}users AS a LEFT JOIN {$wpdb->prefix}bp_activity AS b ON a.ID = b.usercheck WHERE (b.is_activated is null or b.is_activated=1) GROUP BY id ORDER BY rating DESC LIMIT %d", $limit ) ); endif; return prorevs_print_users($users); } function prorevs_users_by_rating_shortcode($atts) { extract(shortcode_atts(array('limit' => 10), $atts)); return prorevs_users_by_rating($limit); }
- You must be logged in to reply to this topic.