• Resolved hsy2

    (@hsy2)


    Hi, i searched for this but i can’t seem to see any convenient answer.
    I’m using the plugin’s custom directories and they are really useful. What i’m currently trying to achieve is to be able to search based on a field present on the current user. For example, this is a snippet i found on the plugins website :”[bps_directory field_35=”Male”]. What i’m trying to have instead is something like : [bps_directory field_35=value_for_current_user]
    Regards

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

    (@dontdream)

    Hi hsy2,

    That feature is not available in the shortcode, but can be implemented in bp-custom.php.

    Let’s say you wish to implement:

    [bps_directory field_35=field_44_of_loggedin_user]

    The code is (note the numbers 35 and 44):

    add_filter ('bps_hidden_filters', 'my_hidden_filters');
    function my_hidden_filters ($filters)
    {
    	$user_id = bp_loggedin_user_id ();
    	$filters['field_35'] = $user_id? xprofile_get_field_data (44, $user_id): '';
    	return $filters;
    }
    Thread Starter hsy2

    (@hsy2)

    Hi Andrea,
    Thanks for your reply.
    This hidden filter will only apply to the specific directory i need this feature on or will it be implemented on all the directories i create ?

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi hsy2,

    As it is, the above code applies to all your directories. If you wish to restrict it to a specific directory page, try this other code instead:

    add_filter ('bps_hidden_filters', 'my_hidden_filters');
    function my_hidden_filters ($filters)
    {
    	if (is_page ('Your Page Name here'))
    	{
    		$user_id = bp_loggedin_user_id ();
    		$filters['field_35'] = $user_id? xprofile_get_field_data (44, $user_id): '';
    	}
    	return $filters;
    }
    Thread Starter hsy2

    (@hsy2)

    Great, it did the trick.
    Thanks a lot for your help Andrea.

    Plugin Author Andrea Tarantini

    (@dontdream)

    You’re welcome!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Dynamic field search’ is closed to new replies.