Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 1 through 10 (of 374 total)
  • Author
    Search Results
  • #274198

    Michele
    Participant

    Hello Trevor,
    can you please confirm the following?

    1) I’ve created a custom results page with the ID (14) of the search form…
    wp-content\themes\my-child-theme-name\search-filter\14.php

    2) … I’ve put all the current php code, except:

    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }

    3) … in the section commented “// the current results.php code here”

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(14)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
    
      if ( $query->have_posts() )
    {
    	?>
    ...

    Is the above procedure correct?
    If I need to translate the website (using WPML), do I need to create a new search form and a new custom results page (so with another ID)?

    Thanks.

    #273770

    Trevor
    Moderator

    Yes, you would need to edit the results.php file, as indicated here (changing the ID shown to match that of your form):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(6745)->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 resuts.php code here (ALL the code from the if ( $query->have_posts() ) line and onwards)
    }
    #270393

    In reply to: Default Results


    Trevor
    Moderator

    Yes, that is possible. I see that you are using our Shortcode method …

    … in which case you should follow the ‘guide to customising’:

    https://searchandfilter.com/documentation/search-results/using-a-shortcode/

    Once you have a copy of the results.php file in a search-filter sub-folder of your theme, you can edit that file, like this (leave the PHP comments at the top outside and before this code):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(10265)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==””)) {
    // code to display the blog post here
    } else {
    // the current resuts.php code here
    }

    #269562

    Cliff Demandt
    Participant

    Hello,

    At the moment i am building a website where people can filter posts. Once filtered it is the intention that it should be possible for people to leave their emailadress. Once they do that i save the “$sf_current_query->get_search_term()” and “$sf_current_query->get_array()” to the database to make it possible to repeat the query.

    Would it be possible to use the saved data to query the results later on? if so with which function? I already tried “set_field_values_array()” but i cannot get it to work.

    The results do not need to be filtered, i just want to check if there are any results afterwords with WP_Query.

    Hope that you can help me with the above, thanks in advance!

    #268679

    Trevor
    Moderator

    1. This will become possible, I think, In V3, due ion a few months, but you would have to write some complex custom JavaScript to do that for now.

    2. You are using the ‘As an Archive’ display results method, so you would have to do some coding in the child theme search.php file to decide which PHP to use for the results by testing the key filter value, which you could fetch using PHP, but again, that would be quite complex, but possible. This thread discusses how to fetch the filters set (or, at least, how to start to work out what they are):

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

    #268116

    Michael Creighton
    Participant

    I tried following this: https://searchandfilter.com/documentation/accessing-search-data/

    on this page: http://staging2.iconcasterwheels.com/shop/?_sfm_caster-wheel-size=10%22&_sfm_caster-wheel-material=Air%2FFlat%20Free&_sfm_caster-fastening-type=Top%20Plate&_sfm_caster-load-capacity=200+300

    Here is the code:

    global $searchandfilter;
    	  $sf_current_query = $searchandfilter->get(56)->current_query();
          //var_dump($sf_current_query->get_array());
    
          $searchArgs = array(
            "str" 					=> '%2$s', 
            "delim" 				=> array(", ", " - "), 
            "field_delim"			=> ', ', 
            "show_all_if_empty"		=> false 
          );
    	  
          
          echo $sf_current_query->get_fields_html(
            array(
              "_sfm_caster-wheel-size",
              "_sfm_caster-wheel-material",
              "_sfm_caster-fastening-type",
              "_sfm_caster-load-capacity"
            ), 
            $searchArgs
          );
    
    

    When I do a var_dump, it shows the info that is expected (hidden for now) — so the id and everything seems to be correct.
    However, when I try to display any of the field values, nothing shows up.

    No errors in console message or anything either.

    I am trying to get it to say “Search Results 10″, Air Flat/Free, Top Plate”

    #267925

    Ben Guth
    Participant

    Hi Trevor,

    Sorry, I think there was a typo on the category search term. I wanted to have an if statement that will check whether the search query has _sft_category. Then if that is true, I wanted to automatically reset the query to remove everything including the _sft_category.

    Currently, I have this code as a start but was stuck on how to call the reset function.

    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1184)->current_query();
    
    if ( $sf_current_query->get_field_string("_sft_category") ) :
      // reset the search query here
    endif;
    

    Thanks!

    #267212

    Edda Puglisi
    Participant
    This reply has been marked as private.
    #267198

    Mark van den Ing
    Participant
    This reply has been marked as private.
    #266877

    Mark van den Ing
    Participant

    Hi,

    we use the Search & Filter Pro on our website to filter a custom posttype (sneakers) with 5 taxonomies (brand, model, color, target audience, age). We created a custom archive for each of these 5 taxonomies.
    We only created one “search form”.

    In the archive for a specific model for example we call the Search & Filter Pro filters using :

    $sf_current_query = $searchandfilter->get(7183946)->current_query();

    We get a nice list of sneakers that match the current model. But what it also shows if we call the filter using a shortcode (<?php echo do_shortcode( ‘[searchandfilter id=”7183946″]’ ); ?>) – so we can filter on color, target audience and age, the brand and model also are there. From a user experience we find this obsolete so we have hidden it using css override in the archive page :

    <style>
    select[name=”_sft_brand[]”] {
    display : none;
    }
    select[name=”_sft_model[]”] {
    display : none;
    }
    </style>

    Unfortunately this results in our page having a lot of (irrelevant) DOM elements which we would like to exclude. This is because all brands and models are still available in the filter (while hidden using CSS). Please note we have a lot of brands and models and we want to keep the page as clean as possible.

    How can we achieve this? Is there a way we can eliminate the DOM elements of brand and model on this particular taxonomy archive? For example on the model taxonomy we want to filter out the brand and model and on the brand page we want to disable the brand.

    Mark

    PS. Please check https://www.solezilla.nl/model/nike-air-max-90/ for an example

Viewing 10 results - 1 through 10 (of 374 total)