Forums Forums Search & Filter Pro Results count

Viewing 8 posts - 1 through 8 (of 8 total)
  • Anonymous
    #254656

    Hi Trevor,

    I wish to display the number of results generated by a query on the search results page. I found how to get the search term in your documentation.
    $sf_current_query = $searchandfilter->get($id)->current_query();
    $term = $sf_current_query->get_search_term();

    How do I get the number of results?

    Thank you,

    Christian

    Trevor
    #254692

    The PHP would look like this, assuming the array returned by the wp_query() function in your child theme is named $query:

    Found <?php echo $query->found_posts; ?> Results

    Anonymous
    #254714

    Trevor,

    I did try this:

    $sf_current_query = $searchandfilter->get($id)->current_query();
    $term = $sf_current_query->get_search_term();
    $count = $sf_current_query->found_posts;

    I returns the term, but not the count. How can I get the results count from the Search and Filter query?

    Thank you,

    Christian

    Trevor
    #254718

    You will not find the count in the $sf_current_query array.

    What display results method are you using?

    Anonymous
    #254723

    Trevor,

    It is a custom search results page. In the header, I wish to display the results count and the search term(s). Below that is a standard loop:

    <?php while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( ‘loop-templates/content’, get_post_format() ); ?>
    <?php endwhile; ?>

    Thank you,

    Christian

    Trevor
    #254725

    You will need to find, within the theme files, what the array is named that the theme wp_query() function feeds its results into. The most common ones used by themes are either $query or $wp_query

    Anonymous
    #254727

    Trevor,

    It works.
    $sf_current_query = $searchandfilter->get($id)->current_query();
    $term = $sf_current_query->get_search_term();
    $count = $wp_query->found_posts;

    Thank you,

    Christian

    Trevor
    #254731

    Thanks for letting me know. I will close this thread for now.

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