• Resolved Ad

    (@dotdoc)


    Hello,

    I’m trying to create a filter for a members directory. What I want:
    – when loggedin users click the menu link to go to the membersdirectory, I want the directory to be prefiltered.
    – the filter should be on field_241 (textfield)
    – the value should be based on the user profile:
    $value = xprofile_get_field_data (241, $user_id);
    When a loggedin user visits the memberdirectory (and has ‘dance’ in userprofile field 241) I would like them to see members that have ‘dance’ in field 241 by default, but be able to search all other ‘values’.

    A hidden field doesn’t work for then they cannot search for other values in field 241.
    – add_filter (‘bps_hidden_filters’, ‘my_hidden_filters’);
    – function my_hidden_filters ($filters);

    Filtering search results seems to have the same problem
    – add_filter (‘bps_search_results’, ‘my_filter_241’);
    – function my_filter_241 ($users)

    A default value doesn’t filter the results when they visit.
    – add_action (‘bps_field_before_search_form’, ‘set_default’);
    – function set_default ($f) {
    if ($f->code == ‘field_241’) {
    …$f->value = xprofile_get_field_data(241, $user_id);…
    }
    }

    I’m hoping there is an obvious solution that I missed.

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

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

    (@dontdream)

    Hello dotdoc,

    You can try the following code:

    add_filter ('bps_request', 'alter_request', 10, 3);
    function alter_request ($request, $type, $form)
    {
    // set the filter if it's not already set
    	if (empty ($request['field_241']))
    		$request['field_241'] = xprofile_get_field_data(241, ... ;
    
    // set the form page to avoid a PHP notice
    	if (empty ($request['bps_form_page']))
    		$request['bps_form_page'] = bps_current_page ();
    
    	return $request;
    }
    Thread Starter Ad

    (@dotdoc)

    Thank you. After adding the $user_id that worked!

    Plugin Author Andrea Tarantini

    (@dontdream)

    You’re welcome, I’m glad I was of help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘default filter’ is closed to new replies.