Forums › Forums › Search & Filter Pro › Total Result Count with ajax
Tagged: ajax, result count, V3
- This topic has 2 replies, 2 voices, and was last updated 6 years, 4 months ago by Anonymous.
-
Anonymous(Private) June 28, 2018 at 8:45 pm #181588
Just trying to figure out a way to obtain a total post count variable that will update when a search is initiated.
Basically, to adhere to the design prescribed for the search page I’m making, I need the post count to appear independent of the results with a static string.
For example: “223 ‘results found'”
I was thinking I might be able to grab that from the global $searchandfilter object but unfortunately none of the values update anyway. Thanks for any advice you may be able to provide!
Ross Moderator(Private) June 28, 2018 at 10:16 pm #181593Hi Tom
How are you trying to do this?
In WP, the variable is always in the query (if your display results method is set to shortcode, this will need adapting, let me know):
global $wp_query; echo $wp_query->found_posts
So you would need to add this in to your template, inside the Ajax Area.
If I am following right though, you would like to display this data outside of the Ajax Area?
In this case, the best thing to do would be to add a hidden element inside the ajax area:
<input type="hidden" value="<?php echo $found_posts; ?>" id="my-found-posts" />
Then with JavaScript, when you have new results loaded with Ajax, you find this variable and append it to the page somewhere.
Take a look at the event
sf:ajaxfinish
which would be the right time to get this variable:
https://searchandfilter.com/documentation/faq/#will-my-lightbox-or-other-fancy-javascript-work-with-this-pluginLet me know if that makes sense, and if I’ve jumped the gun here!
Thanks
-
AuthorPosts