[Resolved] Show only members with Avatars on Member Loop
-
Hello.
So I’m trying to do a member loop that shows only members with avatars.
Here is my code:
template member loop file has this line:
bp_has_members( gd_custom_ids( 'What are your interests?', $interests ) . '&per_page=6&type=random')
functions.php
/********* SEARCH MEMBERS BASED ON PROFILE FIELDS *********/ function gd_custom_ids( $field_name, $field_value = '' ) { if ( empty( $field_name ) ) return ''; global $wpdb; $field_id = xprofile_get_field_id_from_name( $field_name ); if ( !empty( $field_id ) ) $query = "SELECT user_id FROM " . $wpdb->prefix . "bp_xprofile_data WHERE field_id = " . $field_id; else return ''; if ( $field_value != '' ) $query .= " AND value LIKE '%" . $field_value . "%'"; /* LIKE is slow. If you're sure the value has not been serialized, you can do this: $query .= " AND value = '" . $field_value . "'"; */ $custom_ids = $wpdb->get_col( $query ); $i = 0; $user_ids_loop = array(); foreach ($custom_ids as $custom_id){ if(gd_check_avatar($custom_id)){ $user_ids_loop[$i] = $custom_id; $i++; } } if ( !empty( $user_ids_loop ) ) { // convert the array to a csv string $custom_ids_str = 'include=' . implode(",", $custom_ids); return $custom_ids_str; } else return ''; } /********* CHECK IF MEMBER HAVE AVATARS *********/ function gd_check_avatar($user_id){ // Check for avatar. $fbavatar = false; $user_info = get_userdata($user_id); $username=$user_info->user_login; // Check what information is missing? Avatar? Profile info? $username = strtolower($username); $userfbavatar = get_user_meta($user_ID, 'facebook_uid', true); if (!empty( $userfbavatar ) ) { $fbavatar= true; //echo "DEBUG: user has a FB photo<br/>"; } if (bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'no_grav' => true,'html'=> false ) ) != bp_core_avatar_default() ) { $has_photo = true; //echo "DEBUG: user has a photo<br/>"; } if ( $has_photo || $fbavatar) { $avatarchk = true; } if(!$avatarchk){ $avatarchk=false;} return $avatarchk; }
I have ~6,000 members on my site.
I get this error:
[30-May-2014 06:59:51 UTC] PHP Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 64 bytes) in /Users/giova/Sites/lam.dev/wp-content/mu-plugins/wpengine-common/patterns.php on line 331 [30-May-2014 06:59:51 UTC] PHP Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0
I assume that the for loop in function gd_check_avatar() is not helping.
What would be the best way to do this to reduce resources and still get only members with avatars?
Or at least, sort the members so that the first members have an avatar.
Thanks!
Giovanni
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘[Resolved] Show only members with Avatars on Member Loop’ is closed to new replies.