Skip to:

Member Directory: Nav that filters members by first letter of last name

  • gato-gordo


    I am developing a custom Buddypress theme, and I would like to add navigation in the member directory that mimics the functionality of this page on another site:

    Ideally, it would work pretty similarly: the navigation would have a link for each letter of the alphabet, the links would generate bookmarkable urls with query strings, and the member directory would be filtered appropriately at those urls.

    Code for the navigation would be something like this:

    <?php for ($i=0; $i<26 ;++$i ): $this_letter = chr(ord('A') + $i); ?>
         <a href="<?php echo add_query_arg('Last+name+first+letter', $this_letter, bp_get_members_directory_permalink()); ?>"><?php echo $this_letter; ?></a>
    <?php endfor; ?>

    What would be the most appropriate place to hook into to alter the member query? Again, ideally it would be able to grab the query string from the url to dynamically define the filter.

    Right now, there is an XProfile ‘Last Name’ field, which is set up to sync with wp_usermeta#last_name through the plugin, “BP XProfile WordPress User Sync”.

    Using WP 4.1 & BP 2.1.1

Viewing 3 replies - 1 through 3 (of 3 total)

  • modemlooper


    the way to do it is to get letter clicked, access db and collect user ID’s and then filter the loop with those IDs




    Thanks, in case people want to know what the query looks like for something like this:

    $query_string = $_SERVER['QUERY_STRING']; 
      parse_str($query_string, $query_array);
      $letter = $query_array['Last_name_first_letter'];
      $the_field = xprofile_get_field_id_from_name('Last Name');
      $custom_ids = $wpdb->get_col("SELECT user_id FROM {$wpdb->prefix}bp_xprofile_data WHERE field_id = $the_field AND LEFT(value, 1) = '" . $letter . "' ");



    Thanks, gato-gordo! I’m still learning and I’ve read through this post as well as the linked class info above but I’m still having trouble figuring out how to get this to work. Can you provide more info on exactly what you did? Any help would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Member Directory: Nav that filters members by first letter of last name’ is closed to new replies.
Skip to toolbar