• Resolved Diabolo

    (@cebuss)


    Hi Andrea

    Been trying to get the snippet you posted in another thread to work (see https://ww.wp.xz.cn/support/topic/improvement-of-the-search-filter-of-the-buddypress-members-page/).

    Unfortunately, not having much luck.

    Snippet I’ve used:

    add_filter ('bps_hidden_filters', 'my_hidden_filters');
    function my_hidden_filters ($filters)
    {
    	$user_id = bp_loggedin_user_id ();
    	if ($user_id != 0)
    		$filters['field_6'] = xprofile_get_field_data (17, $user_id);
    	return $filters;
    }

    Field_6 is a “I am a” gender field (drop down select box) and 17 is “I am looking for a” gender field (have tried drop down select box, multi select box and checkboxes – ideal solution being the person can select multiple genders).

    If I activate the snippet, it kills the directory and I just get the following warnings:

    Warning: explode() expects parameter 2 to be string, array given in ... plugins/bp-profile-search/bps-search.php on line 164
    
    Warning: explode() expects parameter 2 to be string, array given in ... plugins/bp-profile-search/bps-search.php on line 165
    
    Warning: count(): Parameter must be an array or an object that implements Countable in ... plugins/bp-profile-search/bps-search.php on line 167
    
    Warning: count(): Parameter must be an array or an object that implements Countable in ... plugins/bp-profile-search/bps-search.php on line 168
    
    Warning: count(): Parameter must be an array or an object that implements Countable in ... plugins/bp-profile-search/bps-search.php on line 169
    
    Warning: explode() expects parameter 2 to be string, array given in ... plugins/bp-profile-search/bps-search.php on line 180
    
    Warning: count(): Parameter must be an array or an object that implements Countable in ... plugins/bp-profile-search/bps-search.php on line 181
    
    Warning: explode() expects parameter 2 to be string, array given in ... plugins/bp-profile-search/bps-search.php on line 180
    
    Warning: count(): Parameter must be an array or an object that implements Countable in ... plugins/bp-profile-search/bps-search.php on line 181
    
    Warning: Invalid argument supplied for foreach() in ... plugins/bp-profile-search/bps-search.php on line 185

    Any pointer to where I’m going wrong would be appreciated.

    • This topic was modified 4 years, 5 months ago by Diabolo. Reason: Typo
Viewing 1 replies (of 1 total)
  • Plugin Author Andrea Tarantini

    (@dontdream)

    Hi Diabolo,

    The code you are using works fine if your field 17 is a drop down select box. If it’s a multi select box or checkboxes field instead, you need a slightly different version. Try this:

    add_filter ('bps_hidden_filters', 'my_hidden_filters');
    function my_hidden_filters ($filters)
    {
    	$user_id = bp_loggedin_user_id ();
    	if ($user_id != 0)
    		$filters['field_6_match_any'] = xprofile_get_field_data (17, $user_id);
    	return $filters;
    }
Viewing 1 replies (of 1 total)

The topic ‘Hidden filter’ is closed to new replies.