Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 41 through 50 (of 344 total)
  • Author
    Search Results
  • #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).

    #252346

    Trevor
    Participant

    Does that page use a PHP template file? If it does, using a child theme and a copy of that file in the child theme folder, edit that file to place logic like this in to it:

    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 products output code here
    }

    The ID number must match that of your form.

    Note, if you are using a page builder, this method may not be possible.

    #251712

    Trevor
    Participant

    More complex is needed then.

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query()->get_array();
    $search_cat = $sf_current_query['_sft_category']['active_terms'][0]['name'];
    ?>
    <header class="searсh-header">
    <h1 class="page-title">Résultats de la recherche : <span><?php echo $search_cat;?></span></h1></header>
    #251704

    Trevor
    Participant

    Ah, sorry, I just realized, you want the category to show, NOT the search term?

    That may be a little more complex. This MIGHT work:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    $search_cat = $sf_current_query->get_field_string("_sft_category");
    ?>
    <header class="searсh-header">
    <h1 class="page-title">Résultats de la recherche : <span><?php echo $search_cat;?></span></h1></header>
    #251679

    Trevor
    Participant

    You will need to replace 1234 with your form ID.

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    $search_term = $sf_current_query->get_search_term();
    ?>
    <header class="searсh-header">
    <h1 class="page-title">Résultats de la recherche : <span><?php echo $search_term;?></span></h1></header>

    See if that works?

    #251257

    Trevor
    Participant

    Something like this would do I think (change the ID number to suit):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // show normal loop
    } else {
      // show loop when S&F active
    }
Viewing 10 results - 41 through 50 (of 344 total)