Skip Navigation

[Resolved] Reset filters without resetting results including pagination

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 19 replies, has 2 voices.

Last updated by Minesh 6 months, 1 week ago.

Assisted by: Minesh.

Author
Posts
#2708340

Hello,
Below is the staged website:
hidden link

The login should be the same.

#2708835

Hello Minesh,

Were you able to look at and log into the staged version of the website?

#2709195

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've adjusted the code to "Custom Code" section as given under:

add_filter('wpv_filter_query', 'func_add_missing_url_params', 99, 3);
function func_add_missing_url_params($query_args, $setting,$view_id) {
     
    if($view_id == 7539) {
        global $current_user;
        $current_user_id = $current_user->ID;
      
      $wpv_post_search_name = "custom_wpv_post_search";
      $car_year_name = "custom_car_year";
      $car_make_name = "custom_car_make";
      $car_model_name = "custom_car_model";
      
    
     
   //   if($query_args['paged']==1 and  isset($_GET['wpv_view_count'])) {
            
                      
            if(isset($_GET['wpv_post_search']) and !empty($_GET['wpv_post_search'])){
               
              if ( !metadata_exists( 'user', $current_user_id, $wpv_post_search_name ) ) {
					add_user_meta($current_user_id, $wpv_post_search_name,$_GET['wpv_post_search']);
			  }else{
                update_user_meta($current_user_id, $wpv_post_search_name,$_GET['wpv_post_search']);
              }
              
              
                    
               
             }else if(isset($_GET['car_year']) and !empty($_GET['car_year'])){
             
              		 if ( !metadata_exists( 'user', $current_user_id, $car_year_name ) ) {
						add_user_meta($current_user_id, $car_year_name,$_GET['car_year']);
                      }else{
                        update_user_meta($current_user_id, $car_year_name,$_GET['car_year']);
                      }
              
              
                 
               
             }else if(isset($_GET['car_make']) and !empty($_GET['car_make'])){
                          
                    if ( !metadata_exists( 'user', $current_user_id, $car_make_name ) ) {
						add_user_meta($current_user_id, $car_make_name,$_GET['car_year']);
                      }else{
                        update_user_meta($current_user_id, $car_make_name,$_GET['car_year']);
                      }
 
             }else if(isset($_GET['car_model']) and !empty($_GET['car_model'])){
             			if ( !metadata_exists( 'user', $current_user_id, $car_model_name ) ) {
						add_user_meta($current_user_id, $car_model_name,$_GET['car_year']);
                      }else{
                        update_user_meta($current_user_id, $car_model_name,$_GET['car_year']);
                      }
                   
             }
         
         
         
    //  }else {
       
  
      
    $car_model_value = $car_make_value =  $car_year_value = $wpv_post_search_value = 0;
     if(metadata_exists( 'user', $current_user_id, $car_model_name )){
       $car_model_value = get_user_meta($current_user_id, $car_model_name,true);
     }else if(metadata_exists( 'user', $current_user_id, $car_make_name )){
       $car_make_value = get_user_meta($current_user_id, $car_make_name,true);
     }if(metadata_exists( 'user', $current_user_id, $car_year_name )){
       $car_year_value = get_user_meta($current_user_id, $car_year_name,true);
     }if(metadata_exists( 'user', $current_user_id, $wpv_post_search_name )){
       $wpv_post_search_value = get_user_meta($current_user_id, $wpv_post_search_name,true);
     }
     
 if(isset($_GET['wpv_view_count'])) {
                 //(isset($_GET['wpv_view_count']) and $query_args['paged']>1 ) ) {
      
   					 
      
                    $query_args['meta_query'] = array();
       
     
                    if($wpv_post_search_value){
                    $_GET['wpv_post_search']=$wpv_post_search_value;
                         $query_args['s'] =  $wpv_post_search_value; 
                                   
                    }else if($car_year_value){
                                $_GET['car_year']=$car_year_value;
                                $query_args['meta_query'][] = array('key'=>'car_year',
                                                            'value'=> $car_year_value,
                                                            'type'=>'CHAR',
                                                            'compare'=>'=');
 
                    }else if($car_make_value){
                     		  $_GET['car_make']=$car_make_value;
                      $query_args['meta_query'][] = array('key'=>'car_make',
                                                            'value'=>$car_make_value,
                                                            'type'=>'CHAR',
                                                            'compare'=>'=');

 
                    }else if($car_model_value){
                      		$_GET['car_model']=$car_model_value;
                      $query_args['meta_query'][] = array('key'=>'car_model',
                                                            'value'=>$car_model_value,
                                                            'type'=>'CHAR',
                                                            'compare'=>'=');
                     
                    }
        
        }   
         
      }
        
    //  }
    return $query_args;
}

Can you please confirm it works as expected:
- hidden link

#2709215

Thank you for doing this on the staged site Minesh.

I am afraid the custom code you shared did not have any effect.

Here is an example of a search for parts filtered for the years 2020:
hidden link

And here is page 2 of that search:
hidden link

As you can see the Year filter has been removed after clicking the next page button.

What can we do to prevent pagination from resetting the filtered results so it instead shows the following:
hidden link

While also setting the filters to the default result after the page loads?

#2709236

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I'm not sure why its not working for you.

I can see it working at this end. Please check the following video:
- hidden link

However - I would like to mention that you will have to take it from here as there is no such feature available how you want it to work. You need to simple use the hook I shared "wpv_filter_query" and apply your custom logic to make it work as per your requirement.

More info:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

As the thing is that you have custom JS added that is also submitting the form multiple times and as per our support policy we can not edit custom code you added. As you know I spend enough time on this but unfortunately I'm not sure why its not working at your end but works as this end.

If you still require assistance on this - you can contact any of the certified partners for you any custom requirement and they would be happy to assist you with any of your custom requirement:
- https://toolset.com/contractors/