Filter bp_has_members with bp_ajax_querystring

Home Forums BP Profile Search Forum Filter bp_has_members with bp_ajax_querystring

Viewing 14 posts - 1 through 14 (of 22 total)
  • Author
    Posts
  • #10756 Reply
    cobe
    Guest

    Hi,
    I would like to show only members who have already filled in fields named company.
    How can i do that with bp profile search?
    Thank you

    #10757 Reply
    andrea
    Keymaster

    Hi cobe,

    If your field type is ‘Text Box’, you can show all the members whose field value is not empty with this shortcode:

    [bps_directory field_37_like=%]

    Put the shortcode in the BuddyPress Members page to customize the existing Members directory, or in a new blank page to create an additional directory.

    Replace 37 with the actual field ID of your field.

    #10762 Reply
    cobe
    Guest

    Thank you Andrea, it worked.
    [bps_directory template="members/index-2, members/members-loop-2" field_89_like=%]
    Just one question if i want to make check others filled in fields i will do like that :
    [bps_directory template="members/index-2, members/members-loop-2" field_89_like=% field_90_like=%]

    #10763 Reply
    andrea
    Keymaster

    Yes, you can do that, and only users who filled in both fields will be shown in the directory.

    #10764 Reply
    cobe
    Guest

    That great Andrea, well done!
    How can I make search for all users companies like that:
    One user has 3 companies with xprofile field and each company has the same data like city field(select option : NewYork, California) and activity(Select option :Architectural, Science computer)
    Thank you

    #10768 Reply
    andrea
    Keymaster

    Hi cobe,

    To answer your question I need more information:

    1) Are you using BuddyPress or the BuddyBoss platform?

    2) How did you set up a profile with three “Company” fields?

    #10770 Reply
    cobe
    Guest

    I’m using plugin youzer with buddypress xprofile.
    Each member has xprofile Group:
    Xprofile Group info perso (user first name, user last name, user phone etc…)
    Xprofile Group 1: company1(name company1, phone company1 etc…)
    Xprofile Group 2: company2 (name company2, phone company2 etc…)
    Xprofile Group 3: company3 (name company3, phone company3 etc…)

    #10774 Reply
    andrea
    Keymaster

    Start building your search form using only the first set of fields, i.e. company1, name company1, phone company1.

    Then note the field IDs of your fields, for instance:

    IDs of company1, name company1, phone company1: 12, 14, 16
    IDs of company2, name company2, phone company2: 22, 24, 26
    IDs of company3, name company3, phone company3: 32, 34, 36

    and add this code to your bp-custom.php file:

    add_filter ('bps_field_sql', 'change_query', 10, 2);
    function change_query ($sql, $f)
    {
    	if ($f->code == 'field_12')  $sql['where']['field_id'] = 'field_id IN (12, 22, 32)';
    	if ($f->code == 'field_14')  $sql['where']['field_id'] = 'field_id IN (14, 24, 34)';
    	if ($f->code == 'field_16')  $sql['where']['field_id'] = 'field_id IN (16, 26, 36)';
    	return $sql;
    }

    Please let me know if it works for you!

    #10777 Reply
    cobe
    Guest

    I tried but i got no result
    This is my shortcode for page:
    [bps_directory template="members/index-2, members/members-loop-2" field_89_like=% field_163_like=% field_164_like=%]
    Note : I want te get all members who have already filled in fields comany name1 || company name2 || company name3
    field_89 = Field id of company name 1
    field_163 = Field id of company name 2
    field_164 = Field id of company name 3

    SQL SEARCCH for the 3 companies with select filter city(field_103) and select filter activity (field_94)

    // search entreprise
    add_filter ('bps_field_sql', 'change_query', 10, 2);
    function change_query ($sql, $f)
    {
    	// field_89 = field id company name 1
    	if ($f->code == 'field_89')  $sql['where']['field_id'] = 'field_id IN (189)';
    	// field_89 = field id company name 2
    	if ($f->code == 'field_163')  $sql['where']['field_id'] = 'field_id IN (163)';
    	// field_89 = field id company name 3
    	if ($f->code == 'field_164')  $sql['where']['field_id'] = 'field_id IN (164)';
    	return $sql;
    }
    #10780 Reply
    andrea
    Keymaster

    Hi cobe,

    I suggest you copy my code above, and carefully replace each of my sample field IDs with your actual field ID.

    The logic in the code is:

    // 89 = Field id of company name 1
    // 163 = Field id of company name 2
    // 164 = Field id of company name 3
    
    // if searching for company name 1, search for all the company name fields at the same time
    
    add_filter ('bps_field_sql', 'change_query', 10, 2);
    function change_query ($sql, $f)
    {
    // code for the company name fields
    	if ($f->code == 'field_89')  $sql['where']['field_id'] = 'field_id IN (89, 163, 164)';
    
    // add similar code for the other fields
    }
    #10781 Reply
    cobe
    Guest

    I got error
    Warning: implode(): Invalid arguments passed in C:\wamp64\www\app\wp-content\plugins\bp-profile-search\bps-xprofile.php on line 162
    LINE 162 in bps-xprofile.php
    $query = $sql['select']. ' WHERE '. implode (' AND ', $sql['where']);
    My ids are the same in your code:

    // 89 = Field id of company name 1
    // 163 = Field id of company name 2
    // 164 = Field id of company name 3
    
    // if searching for company name 1, search for all the company name fields at the same time
    
    add_filter ('bps_field_sql', 'change_query', 10, 2);
    function change_query ($sql, $f)
    {
    // code for the company name fields
    	if ($f->code == 'field_89')  $sql['where']['field_id'] = 'field_id IN (89, 163, 164)';
    
    // add similar code for the other fields
    }

    My shortcode is
    [bps_directory template="members/index-2, members/members-loop-2" field_89_like=% field_163_like=% field_164_like=%]

    #10783 Reply
    andrea
    Keymaster

    Sorry, I forgot the last line:

    ...
    ...
    // add similar code for the other fields
    	return $sql;
    }
    #10816 Reply
    cobe
    Guest

    Hi again Andrea, first of all thank you so much for your time.
    I tried your code but i got just list of company name 1 and also search for company_name1 city_name1 activity_name1 but others companies i didn’t get it for members directory annd search this is the code:

    // 89 = Field id of company name 1
    // 163 = Field id of company name 2
    // 164 = Field id of company name 3
    
    // if searching for company name 1, search for all the company name fields at the same time
    
    add_filter ('bps_field_sql', 'change_query', 10, 2);
    function change_query ($sql, $f)
    {
    // code for the company name fields
    	if ($f->code == 'field_89')  $sql['where']['field_id'] = 'field_id IN (89, 163, 164)';
    	if ($f->code == 'field_163')  $sql['where']['field_id'] = 'field_id IN (89, 163, 164)';
    	if ($f->code == 'field_164')  $sql['where']['field_id'] = 'field_id IN (89, 163, 164)';
    
    // add similar code for the other fields
    	return $sql;
    }

    screenshot1
    screenshot2
    screenshot3

    #10817 Reply
    andrea
    Keymaster

    Hi cobe,

    Just to make sure I understand your needs: You have the search form shown in your screenshot1, and when users search for City, Activity or Company Name you wish to search the three City, Activity or Company Name fields in your three field groups.

    Is that correct? If so, that should work fine at the moment, but only for the Company Name field. Can you confirm?

Viewing 14 posts - 1 through 14 (of 22 total)
Reply To: Filter bp_has_members with bp_ajax_querystring
Your information: