Home › Toolset Professional Support › [Resolved] AJAX not working correctly with WPML
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 |
---|---|---|---|---|---|---|
9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - | - | 9: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: Africa/Casablanca (GMT+01:00)
Tagged: How to build a site with Toolset
This topic contains 60 replies, has 3 voices.
Last updated by simonM-5 4 years, 2 months ago.
Assisted by: Jamal.
HI Jamal
Glad you had a good break and again thank you for your persistent helpful attitude in getting us a good result. Much appreciated.
Quick update - I upgraded to WP 5.5 yesterday and can't get into the site at the moment, I'm in contact with my hosting provider to get it up and running ASAP.
Once our site is working again, I will update you again with examples and test cases regarding the sorting.
In the meantime while I get the site up again, you can review the ticket I had with Minesh regarding the known Toolset bug with Last Modified Date:
https://toolset.com/forums/topic/sorting-by-last-modified-not-being-respected-on-front-end/
And regarding the "Favorites" plugin:
It is a tiny plugin which looks like it just adds a column to the database to contain a flag which it stores 1 or 0 in.
The plugin works on any post type, and the flag is set by simply clicking an icon. I added the flag to Nanny Ads and Job Ads and built "My Favourites" Views + Pages to display the shortlist of Ads marked by Users as Favourites.
It works really well, with the exception that it doesn't update duplicates or orginals, only the language which you update the Ad in.
It also adds an Admin column to the custom post type in the back end called "Favorites" where you can see the flag is set to 0 or 1.
Thanks and regards
Simon
Thank you Simon!
We have currently an issue with the last WordPress update. This is already fixed in development and the fix will be included in the next release of Toolset plugins. Read more about it here https://toolset.com/errata/wordpress-5-5-update-triggers-php-notices-in-toolset-blocks/
Regarding the "Favorites" plugin, is it this one https://wordpress.org/plugins/favorites/ or another plugin?
What are the results when you favorite/unfavorite an original post, does it propagate to the duplicate? Is the issue happening in both languages? I'll split a ticket and we'll handle this special case on a separate thread.
Regarding the AJAX search/sorting issue, I'll analyze it when the website and test data are ready.
Hi Jamal
Thanks for the update.
I'm seeing similar issues with several Toolset plugins:
Notice: register_rest_route was called incorrectly. The REST API route definition for toolset/v2/search-posts is missing the required permission_callback argument. For REST API routes that are intended to be public, use __return_true as the permission callback. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) in /var/www/kle1116-204/apps/dev/wp-includes/functions.php on line 5225
Notice: register_rest_route was called incorrectly. The REST API route definition for toolset-views/v1/views/(?P\d+).* is missing the required permission_callback argument. For REST API routes that are intended to be public, use __return_true as the permission callback. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) in /var/www/kle1116-204/apps/dev/wp-includes/functions.php on line 5225
Notice: register_rest_route was called incorrectly. The REST API route definition for toolset/v2/search-posts is missing the required permission_callback argument. For REST API routes that are intended to be public, use __return_true as the permission callback. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) in /var/www/kle1116-204/apps/dev/wp-includes/functions.php on line 5225
Notice: register_rest_route was called incorrectly. The REST API route definition for toolset/v2/search-posts is missing the required permission_callback argument. For REST API routes that are intended to be public, use __return_true as the permission callback. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) in /var/www/kle1116-204/apps/dev/wp-includes/functions.php on line 5225
Notice: register_rest_route was called incorrectly. The REST API route definition for toolset-dynamic-sources/v1/dynamic-sources is missing the required permission_callback argument. For REST API routes that are intended to be public, use __return_true as the permission callback. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) in /var/www/kle1116-204/apps/dev/wp-includes/functions.php on line 5225
And another with WooCommerce:
Notice: register_rest_route was called incorrectly. The REST API route definition for wc/v1/subscriptions/statuses is missing the required permission_callback argument. For REST API routes that are intended to be public, use __return_true as the permission callback. Please see Debugging in WordPress for more information. (This message was added in version 5.5.0.) in /var/www/kle1116-204/apps/dev/wp-includes/functions.php on line 5225
Yes, that's the Favorites plugin I meant. I can't test it yet as I still haven't got the site up yet, I've been battling flames all day on another project 😅and will only get round to this project again this evening I imagine.... Not how I planned my day originally. 🙂
After the 5.5 update, I'm getting all sorts of weird messages like Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 91142104408 bytes) in /var/www/kle1116-204/apps/dev/wp-includes/pluggable.php on line 262.
I'll update you again once our site is up.. Apologies for the delay.
Kind regards
Simon
Hi Simon,
I hoped that you website will be back by today, as I will be on vacation the next week too. For now, I'll set this ticket as waiting for your reply and my colleagues Minesh will continue with you next week.
Best regards,
Jamal
Hi Jamal
Telepathy! I was just about to write to you! 🙂
So, I eventually got our site up again. I had to downgrade and upgrade again.. What a pain in the *** 🙂 The only plugins not working now appear to be the Toolset ones, so that's great news that those issues are already being addressed.
Regarding the Favorites plugin, it is as you describe: the favourite is not being propagated to the original or duplicate.
Example: For a Job Ad created in EN original ("Created 20200810 EN")
1) Click the heart icon in EN and Ad is favourited only in EN original, doesn't get propagated to DE duplicate
2) Unclick the heart icon in EN >> not favourited in any language.
3) Now view the duplicate DE Ad and favourite it >> only the DE duplicate is favourited. The EN original remains unfavourited.
I verified this in the back end too.
I am just about to test the sorting and will update you shortly regarding this!
Best regards
Simon
Hi Jamal
I tested the sorting.
For Job Ads:
- With AJAX off, the criteria appear to be sorting correctly in both languages.
- With AJAX on, the sorting is not working, but I'm actually unable to ascertain the pattern on which it is sorting by, I tried sorting MIN YRS EXPERIENCE and START DATE, for example.
With AJAX on, the LAST MODIFIED sorting is not working also, but this is also under the influence of the custom code from Minesh's previous ticket. At the moment, the custom code is designed for AJAX being off.
If I don't hear back from you today, I wish you a another great holiday!
Kind regards
Simon
Thank you Simon for your feedback, but I'll still need your help, it is not that clear form. Can you please provide an example that will be in this scheme:
- Actions to do: What filters or sorting controls to choose, etc...
- Expected results: What post should be first or last, etc...
- Actual results: What are the erroneous results, etc...
I am pretty sure, you will understand, that we work on several clients' sites every day and that it will be very hard to keep track of each site context.
I tried to check with "nativefamily3" user but it is hard for me to tell what is the correct/wrong result. Maybe I should test with "nativenanny3"! Please provide more details to make it easy for me/us 🙂
Regarding the Favorites plugin, I'll suggest to reach out to the plugin's authors and ask them how they are saving the favorite flag? And ask them if there is any "hook/action/filter" we can use to propagate the flag to the original or duplicate post. We'll then help you produce such a code.
I believe that the plugin's authors are not using the WordPress function "wp_update_post" otherwise, the flag should have been propagated for the original post to the duplicate.
Once you get their reply on this, we can continue on.
Hi Jamal
Apparently my latest update from the 16/8 didn't get to you. That's annoying. I was wondering why I hadn't heard anything ;-). I'll have to re-write it. There's a bug with Toolset Support, so I can't see my open tickets correctly. Already opened a ticket for that. It's with Christian and escalated already to 2nd Tier (https://toolset.com/forums/topic/issue-with-support-technical-support-not-showing-all-open-tickets/)
Anyways, here goes:
Regarding the Favorites plugin:
- I have directed your questions by email to the author of the plugin on 16/8, however I have not heard anything back from him as of 21/8. I will try the forum for the plugin today too.
Regarding the sorting issues:
- Sorting Job Ads by Last Modified works, but only because of custom code provided by Minesh.
With AJAX off in find-a-job-search-and-results-view, sorting appears to work correctly at first.
Steps to reproduce incorrect sorting. Let's use the custom field "MIN YEARS EXPERIENCE" as an example.
1) In find-a-job-search-and-results-view, set Custom Search Settings to "Full page refresh when visitors click on the search button".
2) Switch to User nativenanny2
3) In the menu, click Find a Job. Results are sorted by default to Last Modified date, due to custom code from Minesh (https://toolset.com/forums/topic/sorting-by-last-modified-not-being-respected-on-front-end/)
4) Now, in the SORT BY options, choose eg "Min Years Experience" and then click the Search button. The results are sorted correctly by MIN YEARS EXPERIENCE desc (4,3,3,3,2,2,1).
5) Now, switch the SORT BY to "Start Date" and click Search. Results sort correctly by START DATE desc.
...
Now, in find-a-job-search-and-results-view, change Custom Search Setting set to "Full page refresh when visitors click on the search button with input values auto-updating".
6) Click on Find a Job again to refresh page.
7) Use Available Days as filter, as these are visible in the results. Pick, for example, Saturday. Filters update but results don't yet update (expected).
7) Change SORT BY to "Min Years Experience" again and then click Search. The changing to "Min Years Experience" seems to be ignored and the results are sorted again by Last Modified desc.
8) Now change SORT BY from Last Modified to "Min Years Experience" but leave Saturday selected.
9) Again, Min Years Experience being ignored.
...
Now, in find-a-job-search-and-results-view, change Custom Search Setting set to
"AJAX results update when visitors click on the search button".
10) Click on Find a Job again to refresh page.
11) Choose Saturday under AVAILABLE DAYS in the filters and click Search
12) SORT BY reverts to Post Date, which isn't even an available option (I believe this is the bug Minesh was referring to that is escalated to 2nd Tier).
13) Changing anything in SORT BY and clicking Search finds right results but doesn't sort correctly.
...
Finally, in find-a-job-search-and-results-view, change Custom Search Setting set to "AJAX results update when visitors change any filter values".
14) Click on Find a Job again to refresh page.
15) Choose Saturday again as a filter. Filters update and results update, but Post Date is shown illegally again as an option and changing it to say, Min Years Experience (or anything other than Last Modified), refreshes the results but doesn't sort.
OK, I hope the issue is clear now. Let me know if you need more information.
Kind regards
Simon
Hello Simon, I hope you are safe and doing fine.
I believe that the custom code, suggested by Minesh, for sorting on the modified_date will ALAWYAS apply. Check the code here:
function func_set_default_orderby_modified( $view_args, $view_settings, $view_id ) { $target_view_ids = array(2145,2231); if( in_array($view_id, $target_view_ids ) and !isset($_GET['wpv_filter_submit']) ) { $view_args['orderby'] = 'post_modified'; } return $view_args; } add_filter( 'wpv_filter_query', 'func_set_default_orderby_modified', 101, 3 );
The code will run for views, with IDs 2145 and 2231(this is our view), and when the query var "wpv_filter_submit" is not defined(line 3) . I am not sure, on what cirumstances, the query var "wpv_filter_submit" will be defined.
So, from what I see, so far, the sort will always be set on the modified_date. Maybe if we update the code to something like the following, will work for other sorting options:
function func_set_default_orderby_modified( $view_args, $view_settings, $view_id ) { $target_view_ids = array(2145,2231); if( in_array($view_id, $target_view_ids ) and ( ( isset($_GET['wpv_sort_orderby']) and $_GET['wpv_sort_orderby'] == 'modified') OR ( !isset( $_GET['wpv_sort_orderby'] ) ) ) ) { $view_args['orderby'] = 'post_modified'; } return $view_args; } add_filter( 'wpv_filter_query', 'func_set_default_orderby_modified', 101, 3 );
I wanted to check this with Minesh before getting back to you, but he is not available right now.
Please check the following code, and if you still see a sorting issue let us know what are the expected results:
When (x and y and z), I expect to have (the following sorting (post1, post8, post19)), instead, I got the following sorting (post 19, post1, post8).
Hi Jamal!
Hope you had a nice holiday! 🙂
Thanks for your update. I replaced Minesh's code for Last Modified with the code you presented and repeated my tests. Here are the results:
1) SETTING: Full page refresh when visitors click on the search button
- Can sort by any criteria in any direction successfully on clicking the search button
2) SETTING: Full page refresh when visitors click on the search button with input values auto-updating
- Filters auto-updating
- Cannot sort by anything except Last Modified. If I choose any other SORT BY option and click Search button, SORT BY is reverting to Last Modified desc again.
3) SETTING: AJAX results update when visitors click on the search button
- SORT BY is reverting to the illegal opton "Post Date" in every case after clicking the search button.
4) SETTING: AJAX results update when visitors change any filter values
- Sorting appears to work correctly with this setting. I can sort by all three SORT BY options...
So in summary, only works reliably with setting 1 or 4.
I tested in EN and DE.
Regarding our Favorites issue, unfortunately I've had no feedback from the plugin author nor any answers on the forum regarding my request.... 🙁
https://wordpress.org/support/topic/using-favorites-plugin-with-wpml/
Kind regards
Simon
Hi Simon,
It's great that we have got 1 and 4 workings. At least, we'll have a way until we get it sorted.
To analyze why 2 and 3 are not working, I suspect that the custom code is not completely correct, and I'll need to debug it locally. Just let me know what option you would like to use on your website and I'll take a copy of your website and investigate it locally.
Regarding the Favorites plugin, I feel that we'll be stuck until the author helps us. Otherwise, we'll need to implement this functionality with Toolset.
Let me know your feedback about AJAX options and we'll see what we can do.
Hi Jamal
I think that 1 and 4 are the best options anyway from a user experience point of view.
Option 1 is the most reliable but least user friendly.
Option 4 is the most user friendly, however with Option 4 I see the disadvantage that it doesn't work for those two fields where a user is expected to enter a number in the filters area (MIN YEARS EXPERIENCE and MAX NUMBER OF CHILDREN) since there is no reaction to entering a number, even if one tabs out of the field using the keyboard. The user is still forced to press the Search button to have those criteria considered in the search.
Please feel free to duplicate our site locally and debug.
I wouldn't have a problem using Toolset for Favorites functionality, as long as it is reliable and relatively easy to implement and maintain. Would this mean more custom code?
Kind regards
Simon
Text input fields in the view filters won't trigger the search when the user updates them, he will still need to click on search or to hit "Enter". That's how it works.
You may create a custom Javascript code to trigger the search when the user enters a value on them and just trigger a click on the search button:
... jQuery('form[name=wpv-filter-2231] input[type=submit]').click() ...
Or you may convert these fields to be a select control, which will trigger the search automatically. I already converted the "MIN YEARS EXPERIENCE" field. Please check and let me know if that's a viable workaround for you.
I prepared a copy of your website for download, but I wonder what option (2, or 3) would you like me to analyze. If you will be using option 4, I won't analyze it further, unless there is still an error somewhere.
Regarding the implementation of "Favorites" with Toolset, I don't think it would be difficult to implement without custom code. But your requirement to sync the favorite flag across languages will still require custom code to implement it.
Hi Jamal
I like the idea of the select boxes. 🙂 The numbers of options / the numbers in both boxes should be relatively small anyway. I'll run this by my business partner and see what she thinks.
I think we will go with either Setting 1 or 4, so perhaps it doesn't make sense for you to waste time investigating Settings 2 and 3 as mentioned above. However still there appears to be a bug when using option 4 (AJAX results update when visitors change any filter values). Steps to reproduce:
1) Using user nativenanny2, click Find a Job. Results shown and sorted by Last Modified as expected.
2) Now change any filter option, eg MIN YEARS EXPERIENCE or a click one of the AVAILABLE DAYS. The SORT BY is jumping again to "Post Date", which shouldn't be a valid option.
I think this is the same original bug Minesh referred to showing its ugly head again...
Kind regards
Simon
Hi Simon,
I tried to reproduce the sorting issue, but I was not able. It seems to me that the sorting is correct for the three available sorting options. I recorded a short video, please let me know if I missed something.
hidden link
Best regards,
Jamal