Home › Toolset Professional Support › [Resolved] Stored user data can't be edited during search view
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 6 replies, has 2 voices.
Last updated by Minesh 4 months, 3 weeks ago.
Assisted by: Minesh.
Hi,
Previous topic for more info - https://toolset.com/forums/topic/split-user-stored-preference-data-changes-search-results-generic-field-default-value-edit-form/#post-2708877.
The user stored data still does not work like I want it to, but the biggest problem is that now, user can't "reset" with search filter their search.
So, user fills a form in their account, then automatically goes to property search with the predefined data from the form. So far, so good, but when in search view, the reset button no longer resets their filters and they have to go back to account to change them.
I'm not good with php, so I don't know how to tell the code to reset the predefined filters wherever the certain reset button appears.
Code:
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;
}
add_shortcode('is_pms_member','func_is_pms_member');
function func_is_pms_member(){
$status = pms_is_member();
return $status;
}
Hello. Thank you for contacting the Toolset support.
Well - you should define your requirement before you raise the ticket so the solution should be shared according to your requirement. If you just make just parts and solve the issue and then change your requirements later that makes things happen which we have now.
Well - as you see with the code I sahred:
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; } add_shortcode('is_pms_member','func_is_pms_member'); function func_is_pms_member(){ $status = pms_is_member(); return $status; }
We are getting the user's custom field value:
$user_city = get_user_meta($user_id,'city',true); $user_listing_category = get_user_meta($user_id,'listing_category',true);
And if its found we hook in the query filters:
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'); }
So, you should modify the above code accordingly and check and modify the code about reset button and if you see the reset is triggered then you should not hook-in the above query filters.
Hi,
Thank you, I suppose my problem was not defined correctly, so I'll try and do it better now.
The user form works - it's storing user data (city and listing category). I've included past tickets so it's easy to retrace what has been done.
The problem now is: after user data is stored (city and listing category), the user is redirected to a search based on that data.
The search view's "reset" button does not reset the data and I'm asking if that can be done?
On what page you have search and from where I can reset it?
Can you please share all those problem URLs and admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
So when user submit the form here: hidden link
User is redirected on the following search page:
- hidden link
Now, at this time the predefined city and listing category from user form is applied to the above view result.
Now, if he start searching applying other filters it will keep the predefined city and listing category of user form.
Now, once user click on reset button, it should remove the predefined city and listing category of user form. - right?
Do you mean that the predefined city and listing category of user form is only applied when user is redirected to search result page from the following form: hidden link - correct?
So when user submit the form here: hidden link - YES
User is redirected on the following search page:
- hidden link - YES
Now, at this time the predefined city and listing category from user form is applied to the above view result. - YES
Now, if he start searching applying other filters it will keep the predefined city and listing category of user form. - YES
Now, once user click on reset button, it should remove the predefined city and listing category of user form. - right? - YES
Do you mean that the predefined city and listing category of user form is only applied when user is redirected to search result page from the following form: hidden link - correct?
- User is redirected with assigned city&listing category to search view. In search view - user must be able to change search filters (reset button, city, category etc.), but that should not change user defined city&listing category from user form.
The idea is: user goes to search and sees only defined city&listing category, based on their choice from their account.
User views the search and decides to change filter to see different listings. This changes only the current search, not user city&listing category from account.
Can you please check now.
I've adjusted the code added to "Custom Code" section code snippet 'tooset-custom-code' 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; if((isset($_GET['cred_referrer_form_id']) and !isset($_GET['wpv_view_count']))) { $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; }
Can you please confirm it works as expected.
Hi,
You're amazing! It's working - thank you.