Skip to:
Content
Pages
Categories
Search
Top
Bottom

display only the list of members who match with a search criterion


  • HDcms
    Participant

    @hdcms

    Hello,

    The idea is to display only the list of members who match with a search criterion “radio button” (or if possible checkbox) that inserted the logged in member in his profile (eg I am looking for a : developer=”buddypress” 🙂

    I found the following function but how to add filter on the display of the list of members in bp-custom.php?

    function my_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 );
      
      if ( !empty( $custom_ids ) ) {
        // convert the array to a csv string
        $custom_ids_str = 'include=' . implode(",", $custom_ids);
        return $custom_ids_str;
      }
      else
       return '';
       
    }

    Members Loop

    Regards

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

  • HDcms
    Participant

    @hdcms

    Hello,

    I put my search field “radio button”: “I’m looking for”
    I am waiting for the display of the:
    list of all the members who checked “H” if the member put “I search” = “H”
    list of all members who checked “F” if the member put “I search” = “F”
    Off right now, everything is mixed

    add_filter( 'I'm looking for', 'my_custom_ids', 10, 2 );
    function my_custom_ids( $field_name, $field_value = '' ) {
    ...

    HDcms
    Participant

    @hdcms

    Hello,
    I think I understand, it’s a bit more complicated. The simplest is to explain as for a dating site.
    Filter the display of the list of members is done with a single criterion.
    I display the criterion “I research” of my profile = the criterion “I am” of all the other profiles
    Regards


    HDcms
    Participant

    @hdcms

    HI,
    I got a message from the theme author, but if you could help me or give me an example?

  • “The member loops uses the bp_ajax_querystring function to build member results aslo this function has a filter with you can alterate the query, the filter it’s : bp_ajax_querystring / https://codex.buddypress.org/developer/function-examples/bp_ajax_querystring/

    So there should be made a custom function/s that check it’s there it’s member directory and only then to run that function and also should be builded the logic of your flow.”


HDcms
Participant

@hdcms

HI,

I’m trying to filter the buddypress members in the list of members and display them in descending order of precedence on a numeric xprofile field (0 to 10).
Example of filter xprofile field “I search” = xprofile field “I am”

I found the function that should work, but I can not do the query:

function my_bp_loop_querystring( $query_string, $object ) {
if ( ! empty( $query_string ) ) {
$query_string .= ‘&’;
}
// $query_string .= ‘per_page=2’; //works
$jerecherche = xprofile_get_field_data(‘Je recherche’, $user_id, $multi_format = ‘comma’ );
$query_string .= ‘search_terms=true&per_page=2’; // <del datetime="2018-01-17T10:23:06+00:00">works</del>

return $query_string;
}
add_action( ‘bp_legacy_theme_ajax_querystring’, ‘my_bp_loop_querystring’, 20, 2 );

HDcms
Participant

@hdcms

HI,

I’m trying to filter the buddypress members in the list of members and display them in descending order of precedence on a numeric xprofile field (0 to 10).
Example of filter xprofile field “I search” = xprofile field “I am”

I found the function that should work, but I can not do the query:

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar