Search Results for 'current_query'

Forums › Forums › Search › Search Results for 'current_query'

Viewing 10 results – 41 through 50 (of 385 total)
  • Author
    Search Results
  • #254718

    In reply to: Results count


    Trevor
    Participant

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

    What display results method are you using?

    #254714

    In reply to: Results count


    Anonymous
    Inactive

    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

    #254656

    Anonymous
    Inactive

    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

    #254383

    Trevor
    Participant

    Are you using our Shortcode Display Results method. If not, you would need to be using a method that uses a (simple) theme PHP template and be abel to add code like this (the ID number needs to match your form):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // the current (filtered) posts output code here
    }
    #254268

    Trevor
    Participant

    So, the logic would look something like this (the ID would match that of the search form):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // the code to display the 8-10 default houses
    } else {
      // the normal results loop code here
    }

    But, I am not sure Avada uses traditional templates, so this may be difficult to code. In the past, other Avada users have needed to use a third party grid plugin, such as this method (which does not offer the option to do as you want in this case):

    https://searchandfilter.com/documentation/3rd-party/post-grid/

    #253273

    Trevor
    Participant

    First, the Active Query Object. How are your results being out put on the results page? Many method uses frameworks and/or page builders, and with these, you really do not have access to the data you need. Instead, the page the outputs the results must be using a PHP template. So, you fist need to describe to me the Display Results Method that the form uses, and any other useful infomartion.

    Second. I am not aware how this can be done, but, again, if you are using a PHP template, you MIGHT be able to do this.

    This post describes how to retrieve the data from within the PHP template of the results page:

    https://support.searchandfilter.com/forums/topic/acf-post-meta-fields-in-current_query-result/#post-249704

    This will require intermediate PHP coding skills.

    #253147

    Trevor
    Participant

    The code you would need is:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(9490)->current_query()->get_array();
    echo $sf_current_query['_sfm_UnitLocation']['active_terms'][0]['name'];

    Look carefully, as only the ‘global’ line is the same.

    Note, if you are using Ajax on the page, you may need to make sure that the page title is inside the Ajax Container, otherwise it will not refresh and change.

    #253140

    Anonymous
    Inactive

    Just FYI, I have added this code within my #main container on the archive template. Nothing shows.

    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(9490)->current_query();
    	echo $sf_current_query->get_field_string("_sfm_UnitLocation");
    #253043

    In reply to: access search data


    Trevor
    Participant

    1. Yes, using PHP. If your results are being output by a page builder or grid plugin, this is not possible. Similarly, themes that are using frameworks, instead of traditional templates, you would need to use our Shortcode results method, which uses a PHP template.
    2. Only with very complex JavaScript, which even I would not attempt to craft.

    For #1, this post explains a bit for you. Note, the code would have to go INSIDE the Ajax Container in the PHP template:

    https://support.searchandfilter.com/forums/topic/acf-post-meta-fields-in-current_query-result/#post-249704


    Trevor
    Participant

    Having said that, you might be able to do it using this filter:

    https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object

    … where the PHP would first have to check to see if a search has been done, and then conditionally remove the numbers in brackets from the labels. But that might slow things down a little.

    The general method to detect if a search has been made is this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // code here to remove the counts
    }

    Replace the ID number with that of your form.

    As the count is always in brackets, you could find the position of the last instance of ( in the string, and trim the string to that left most number of characters of the string (minus 1 I think, as there will be a space also).

Viewing 10 results – 41 through 50 (of 385 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.