Forums Forums Search & Filter Pro Total Result Count with ajax

Tagged: , ,

Viewing 3 posts - 1 through 3 (of 3 total)
  • Anonymous
    #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
    #181593

    Hi 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-plugin

    Let me know if that makes sense, and if I’ve jumped the gun here!

    Thanks

    Anonymous
    #182029

    That is fantastic! Thank you so much for the info!!

Viewing 3 posts - 1 through 3 (of 3 total)