BP Profile Search › Filter out users if value is null
-
AuthorPost
-
James
GuestHi,
I’d like to set up a form + associated directory that only returns results where a particular field has any value.
e.g. For directory “A”, only show results where value 1 is not null, but still have the ability for directory “B” to show results from all users.
I suspect that my_hidden_filters function would be helpful, but not sure of the syntax from the examples in the forum.
James
GuestI think I figured it out the is not null part with the code below, but not sure on how to only apply this filter to a single directory.
Any help appreciated!
add_filter ('bps_hidden_filters', 'my_hidden_filters'); function my_hidden_filters ($filters) { $user_id = bp_loggedin_user_id (); $f2 = xprofile_get_field_data (2, $user_id); if ($user_id != 0 && !is_null($f2)) { $filters['field_2'] = $f2; } return $filters; }andrea
Plugin AuthorHi James,
To limit your hidden filters to a specific directory, you can use this code:
add_filter ('bps_hidden_filters', 'my_hidden_filters'); function my_hidden_filters ($filters) { if (!is_page('Page Title')) return $filters; // add your hidden filters for 'Page Title' here return $filters; }Replace ‘Page Title’ with the actual title of the page where you put the [bps_directory] shortcode.
By the way, the code you posted adds the filter only if the current user has a non-empty value in his/her own profile. Is that what you need?
James
Guesthey, thanks
and, no – I had hoped for the directory to only return results for all users with non-null values.
andrea
Plugin AuthorIf 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=%]Does that work for you?
James
GuestHi,
Yes that worked, thanks!
-
AuthorPost