Forums › Forums › Search & Filter Pro › Update total results count after ajax
- This topic has 8 replies, 3 voices, and was last updated 7 years, 7 months ago by Ross.
-
Anonymous(Private) March 28, 2017 at 5:03 pm #99956
I’ve been searching thru documentation to find either a jquery method or some other way to update the total # of results counter returned the user when the results are updated via ajax.
The results count works correctly on initialization b/c it’s using the original PHP $wp_query->found_posts but after the user interacts with the form and filters, I don’t have a way to update the returned results count.
I’ve been looking thru the docs for hours and can’t find how to do this.
Ex: 40 results found -> 23 results found
Ross Moderator(Private) March 29, 2017 at 5:41 pm #100222Where are you displaying this count?
If its inside your ajax container, then it will auto update when the results update.
If you want to change something dynamically elsewhere on the page, then I would recommend to store the variable in a hidden
input
, inside your ajax container.Then when your results are updated, this hidden input is also updated.
You can then grab the var with JS and update what you need on your page, you’ll just need to detect when our ajax request has finished so you can grab the new var, which can be found first question:
https://www.designsandcode.com/wordpress-plugins/search-filter-pro/faqs/
Hope that helps
Anonymous(Private) March 29, 2017 at 6:37 pm #100238I’ve actually tried using the jquery calls listed in the FAQ and none of them work.
I have tested to make sure that the actual function they reside in is called (with a console.log) but the actual firing of the sf:ajaxfinish / sf:ajaxstart / sf:init never triggers the console.log output.
I am trying to display the count outside of the ajax container, but there doesn’t seem to be a way for me to grab the results number once the ajax has run. Placing the the front-end output within the ajax container is fine for the first load, but once the ajax refreshes, it disappears as the plugin is replacing everything within the ajax loading div with the new article content.
I’m also curious as to how to access the results count var as there doesn’t seem to be documentation about that variable either.
Ross Moderator(Private) March 29, 2017 at 6:43 pm #100241Hi Erik
Ok so lets roll it back a second.
1) What display method are you using in the
display results
tab?$query_name->found_posts
is the correct way to grab this, but the$query_name
may vary depending on your display method / setup2) The ajax events – to get this working did you try to wrap them in a function like the last example in the FAQs? Thats usually the issue as you may be hooking into the events too early (when jQuery or S&F has not yet init), try:
(function ( $ ) { "use strict"; $(document).on("sf:ajaxfinish", ".searchandfilter", function(){ console.log("S&F ajax finished"); }); }(jQuery));
Let me know how you get on and if you can supply a URL to see where you’ve got to that would really help.
Best
-
AuthorPosts