Skip Navigation

[Resolved] Split: User stored preference data, changes search results – generic field default value edit form

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 3 replies, has 2 voices.

Last updated by Minesh 5 months, 1 week ago.

Assisted by: Minesh.

Author
Posts
#2708728

Hi,
It's working. The listings show up after I "save" the user form in tab preference, but once I return to it again - it's reset.
I select option A, I go to search results, return to the tab and my selection in gone.
The search selection shows up, even if the user form no longer is selected correctly(reset on the tab preference).

#2708731

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

You will have to conditionally display the field on edit form so that if the user field city and listing_category has value then you should set the default value for the generic field otherwise not.

I've adjusted the code for your form as given under:

[creduserform]
[cred_field field="form_messages" class="alert alert-warning"]
<div class="row">
<div class="form-group col-sm-6">
<label for="%%FORM_ID%%_city">[cred_i18n name='city-label']Област[/cred_i18n]</label>

[wpv-conditional if="( '[wpv-user field='city']' eq '')"]

 [cred_generic_field type='select' field='city']
{
"required":1,
"persist":1,
"default":["Благоевград"],
"options":[{"value":"Благоевград","label":"Благоевград"},{"value":"Бургас","label":"Бургас"},{"value":"Варна","label":"Варна"},{"value":"Велико Търново","label":"Велико Търново"},{"value":"Видин","label":"Видин"},{"value":"Враца","label":"Враца"},{"value":"Габрово","label":"Габрово"},{"value":"Добрич","label":"Добрич"},{"value":"Кърджали","label":"Кърджали"},{"value":"Кюстендил","label":"Кюстендил"},{"value":"Ловеч","label":"Ловеч"},{"value":"Монтана","label":"Монтана"},{"value":"Пазарджик","label":"Пазарджик"},{"value":"Перник","label":"Перник"},{"value":"Плевен","label":"Плевен"},{"value":"Пловдив","label":"Пловдив"},{"value":"Разград","label":"Разград"},{"value":"Русе","label":"Русе"},{"value":"Силистра","label":"Силистра"},{"value":"Сливен","label":"Сливен"},{"value":"Смолян","label":"Смолян"},{"value":"Софийска област","label":"Софийска област"},{"value":"София","label":"София"},{"value":"Стара Загора","label":"Стара Загора"},{"value":"Търговище","label":"Търговище"},{"value":"Хасково","label":"Хасково"},{"value":"Шумен","label":"Шумен"},{"value":"Ямбол","label":"Ямбол"}]
}
[/cred_generic_field]
  
 
[/wpv-conditional]

  [wpv-conditional if="( '[wpv-user field='city']' ne '')"]
  [cred_generic_field type='select' field='city']
{
"required":1,
"persist":1,
"default":"[wpv-user field='city']",
"options":[{"value":"Благоевград","label":"Благоевград"},{"value":"Бургас","label":"Бургас"},{"value":"Варна","label":"Варна"},{"value":"Велико Търново","label":"Велико Търново"},{"value":"Видин","label":"Видин"},{"value":"Враца","label":"Враца"},{"value":"Габрово","label":"Габрово"},{"value":"Добрич","label":"Добрич"},{"value":"Кърджали","label":"Кърджали"},{"value":"Кюстендил","label":"Кюстендил"},{"value":"Ловеч","label":"Ловеч"},{"value":"Монтана","label":"Монтана"},{"value":"Пазарджик","label":"Пазарджик"},{"value":"Перник","label":"Перник"},{"value":"Плевен","label":"Плевен"},{"value":"Пловдив","label":"Пловдив"},{"value":"Разград","label":"Разград"},{"value":"Русе","label":"Русе"},{"value":"Силистра","label":"Силистра"},{"value":"Сливен","label":"Сливен"},{"value":"Смолян","label":"Смолян"},{"value":"Софийска област","label":"Софийска област"},{"value":"София","label":"София"},{"value":"Стара Загора","label":"Стара Загора"},{"value":"Търговище","label":"Търговище"},{"value":"Хасково","label":"Хасково"},{"value":"Шумен","label":"Шумен"},{"value":"Ямбол","label":"Ямбол"}]
}
[/cred_generic_field]
  		
  [/wpv-conditional]

  
</div>  
<div class="form-group col-sm-6"> 
              <label for="%%FORM_ID%%_listing-category">[cred_i18n name='city-label']Категория TBC[/cred_i18n]</label>
[wpv-conditional if="( '[wpv-user field='listing_category']' eq '')"]
[cred_generic_field type='select' field='listing_category' class="" urlparam=""]
          {
"required":1,
"persist":1,
"default":[77],
"options":[ [wpv-view name="get-all-listing-category-terms"] ]
}
[/cred_generic_field]
 [/wpv-conditional]
  
  [wpv-conditional if="( '[wpv-user field='listing_category']' ne '')"]
[cred_generic_field type='select' field='listing_category' class="" urlparam=""]
          {
"required":1,
"persist":1,
"default":"[wpv-user field='listing_category']",
"options":[ [wpv-view name="get-all-listing-category-terms"] ]
}
[/cred_generic_field]
 [/wpv-conditional]
  
  
</div>
</div>
<div class="row">
<div class="form-group col-sm-12"> 
	[cred_field field='form_submit' output='bootstrap' value='Запази' class='btn btn-primary btn-lg']
</div>
</div> 
[/creduserform]

Where as you can see I've added the conditional shortcode to display the form field and accordingly set the default value for it.

More info:
- https://toolset.com/documentation/legacy-features/views-plugin/using-shortcodes-in-conditions/
- https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-user

#2708877

Hi,
I've tested it, but it's not showing more than one correct search.

I've tested it with Враца and the search results were indeed the same. Went back, the selected were correct, but when I changed it to Ловеч, the search results were still Враца.

I've tested it trough payed member "test". Merged tab "абонамент" and "платен абонамент" together.
Tried changing types to multiselect, checkboxes - still the same result.

#2709430

Minesh
Supporter

Languages: English (English )

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

Can you please check now:

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

add_filter('wpv_filter_query', 'func_user_selected_city_listing_cat', 99, 3);
function func_user_selected_city_listing_cat($query_args, $setting,$view_id) {
  
  		if($view_id == 9980 and is_user_logged_in() and pms_is_member() ) {
          
          		global $current_user;
                $user_id = $current_user->ID;
                
				$user_city = get_user_meta($user_id,'city',true);
                $user_listing_category = get_user_meta($user_id,'listing_category',true);
          
          		
               
          		if($user_city) {
                  	 $query_args['meta_query'][] = array('key'=>'city',
                                              'value'=>$user_city,
                                              'type'=>'CHAR',
                                              'compare'=> '=');
                  
                }  
              if($user_listing_category) {
                  
                  	$query_args['tax_query'][] = array(
                                                'taxonomy'=> 'listing_category',
                                                'field' => 'id',
                                                'terms' => $user_listing_category,
                                                'operator' => 'IN');
                }
		}  
  
      
  
    return $query_args;
}

I've also disabled the view cache for both "Search-results-clean-payed" and "Search-results-clean" views.

Can you please confirm it works as expected now.