Reply To: Adding profile fields to members directory
Hi @antipole,
from non-epert to non-expert, i’ll try to explain what i understood from your previous request…
You want to show a profile filed value on the member directory and this value should be searcheable in the same way as on a profile. Right ?
On members directory, we need a field name, a field value, a user ID and a search link.
This line of code will fetch the correct field, associated to the user ID:
$value = xprofile_get_field_data('Ovni model', bp_get_member_user_id() ) )
This line will build the url for that value
$search_url = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() );
And this line will build the output. I use a div with a class name. I recommand you keep it as is and add your custom style from within your child-theme style.css. Inline style is not necessary here.
$clickable = '<div class="click_dir"><a href="' . esc_url( $search_url ) . '" rel="nofollow">' . $value . '</a></div>';
And this generate the output: echo $clickable;
And finally, we add our custom filter to the existing by using add_fliter( $filter_name, $my_filter):
add_filter ( 'bp_directory_members_item', 'make_directory_profile_field_searchable' );
That’s it.
My snippet let you add such a clickable field. The field name is “ovni model”.
The code is first calling that field, and before the final output on members directory, we add a clickable search url. This is a strictly BP way to add an url to a (field)value. This snippet doesn’t need another function to work.
The field, from a profile perspective, will be Name Ovni model: value flying saucer. The link structure will be your-site/members/username/?s=flying_saucer.
The snippet use the same structure on members directory and you’ll get the same result.
Guess you don’t need the additionnal function add_info_to_members_loop.
Try first and struggle after, it’s better for your karma ! 😉