New version – template and filter

Home Forums BP Profile Search Forum New version – template and filter

This topic contains 8 replies, has 2 voices, and was last updated by  andrea 1 week, 1 day ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #10414 Reply

    Jennifer

    Hi! I have 2 problems new with the new version, can you help me?
    ———-First——————–
    1. make exact copy of /plugins/bp-profile-search/templates/members/bps-form-default.php and place it in Child-Theme/buddypress/members/new-template.php

    2. Put this in functions php:

    add_filter ('bps_templates', 'add_template');
    function add_template ($templates)
    {
        $templates[] = 'members/new-template';
        return $templates;
    }

    and when the option open the option it didnt appear like the template default.
    Image: https://prnt.sc/qz77jl

    —————-Second————
    Time before you give me this code for filter for location

    add_filter ('bps_hidden_filters', 'directory_filters');
    function directory_filters ($filters)
    {
    	global $wpdb;
    
    	$user = bp_loggedin_user_id ();
    	if (empty ($user))  return $filters;
    
    	$table_name = $wpdb->prefix. 'bds_locations';
    	$query = "SELECT * FROM $table_name WHERE user_id = $user AND field_id = 52;";
    	$value = $wpdb->get_row ($query);
    
    	if (!empty ($value))
    	{
    		$filters['field_62_distance']['distance'] = 100;
    		$filters['field_62_distance']['units'] = 'km';
    		$filters['field_62_distance']['location'] = $value->location;
    		$filters['field_62_distance']['lat'] = $value->lat;
    		$filters['field_62_distance']['lng'] = $value->lng;
    	}
    
    	return $filters;
    }

    is it compatible? because now this filter the user with a different location.

    thanks very much!!!

    #10417 Reply

    andrea
    Keymaster

    Hi Jennifer,

    1. Try to lower the priority of your filter, so it runs after the Kleo code.

    add_filter ('bps_templates', 'add_template', 20);

    2. That code is still valid. Please double check the IDs 52 and 62, and the value of the field 52 for the logged-in user. If they are correct, I’ll need more information to understand the issue.

    #10418 Reply

    Jennifer

    Hi Andrea!
    1) it works perfectly!
    2) I add to the code $bp global.. but i notice that the field 52 was import by a form, so the field only have the complete name but it didnt save the lat and long (table bds_locations appears like 0). so this dont work.
    is any way to filter this?
    Thanks very much!

    #10419 Reply

    andrea
    Keymaster

    Hi Jennifer,

    Which of the following is true in your case?

    1. The bds_locations table is completely empty.

    2. The bds_locations table is populated, and in all the rows the lat and lng values are 0.

    3. The bds_locations table is populated, and in a few rows the lat and lng values are 0.

    4. Other – please detail.

    #10420 Reply

    Jennifer

    Hi Andrea!
    The case is the number 3. because the value is imported with this function from the form (the form use google of autocomplete but in the bd only save the name of location).
    sometimes is full when i complete in the front end on the page for test and use the field with autocomplete.

     //fragment of code
    
    if (function_exists('bp_core_signup_user')) {
            // Profile fields
            $usermeta = array(
                     'field_43' => $form->getValueText('quform_5_44'),
            );
            $usermeta['profile_field_ids'] = '43';
    #10421 Reply

    Jennifer

    https://prnt.sc/qzplkq with var_dump($value);

    #10424 Reply

    andrea
    Keymaster

    When you get the location from a different form, as in your case, you also need to update the bds_locations table with the lat-long values.

    Does your form provide the lat-long coordinates too?

    #10425 Reply

    Jennifer

    Thanks Andrea!! I found a way with google api to get lat and long and update the bds_locations table with the lat-long values.. Now it works!!
    It would be perfect if the distance would appear likeas the image in the direction.https://prnt.sc/qzxp6x
    (When I type the address in the search box manually without applying the php filter it works, but with the filter I only get the results)

    #10426 Reply

    andrea
    Keymaster

    Hi Jennifer,

    You’re welcome! Unfortunately at this time it’s not possible to show the distance using a hidden filter. I’m taking a note to study that feature for a future release.

Viewing 9 posts - 1 through 9 (of 9 total)
Reply To: New version – template and filter
Your information: