• Resolved Hustl

    (@wearecrunch)


    Hi,

    I have created extended profile fields for my members, that I use for filtering search results. Each member has a role that can be either: ‘Mentor’, ‘Mentee’, ‘Mentor and Mentee’, ‘Not in the mentor program’.

    If the role ‘Mentor’ or ‘Mentee’ is selected the members with the role ‘Mentor and Mentee’ should also be shown. Is there a way to select two filters when a specific option is chosen?

    Buddypress Version 6.3.0
    Wordpress Version 5.5.3

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Andrea Tarantini

    (@dontdream)

    Hi wearecrunch,

    I suggest you select the search mode ‘is one of’ for your role field. This way your users will be able to select one filter or both, according to their preference.

    Thread Starter Hustl

    (@wearecrunch)

    Hi Andrea, thank you for your reply. Unfortunately your suggestion does not solve my challenge as I don’t want to allow the user to select multiple roles at the same time.

    Is there any options to customize the search result or filters via functions.php?

    Plugin Author Andrea Tarantini

    (@dontdream)

    Yes, you can add this code to your functions.php file:

    add_filter ('bps_field_sql', 'change_query', 10, 2);
    function change_query ($sql, $f)
    {
    	if ($f->code == 'role' && $f->value != 'subscriber')
    	{
    		$sql['where']['set_match_any'] .= " OR (meta_value LIKE '%:\\\"administrator\\\";%')";
    	}
    	return $sql;
    }

    Replace ‘subscriber’ with the internal name of ‘Not in the mentor program’, and ‘administrator’ with the internal name of ‘Mentor and Mentee’.

    Thread Starter Hustl

    (@wearecrunch)

    Hi again,

    I inserted this into my functions.php but it still only shows “Mentee” when I click that filter and not both “Mentee” and “Mentor and Mentee”. Is the code below correct?

    add_filter (‘bps_field_sql’, ‘change_query’, 10, 2);
    function change_query ($sql, $f)
    {
    if ($f->code == ‘role’ && $f->value != ‘Not in the mentor program’)
    {
    $sql[‘where’][‘set_match_any’] .= ” OR (meta_value LIKE ‘%:\\\”Mentor and Mentee\\\”;%’)”;
    }
    return $sql;
    }

    Plugin Author Andrea Tarantini

    (@dontdream)

    Sorry, I assumed you were using the WordPress role, but now I see you are using a BP profile field. So the correct code is:

    add_filter ('bps_field_sql', 'change_query', 10, 2);
    function change_query ($sql, $f)
    {
    	if ($f->code == 'field_24' && $f->value != 'Not in the mentor program')
    	{
    		$sql['where']['text_is'] .= " OR (value = 'Mentor and Mentee')";
    	}
    	return $sql;
    }

    You can use it as it is, and please let me know if it works for you!

    Thread Starter Hustl

    (@wearecrunch)

    Thank you! That was exactly what I meant, works perfectly ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Customize search result’ is closed to new replies.