Forums Forums Search Search Results for 'sf_current_query'

Viewing 10 results - 161 through 170 (of 318 total)
  • Author
    Search Results
  • #181171

    Trevor
    Participant

    You could use PHP to look at the array that holds the filter arguments, and conditionally load different code in the same template. Again, that is custom coding.

    To start with, put this code on the results page in a suitable place:

    $sf_current_query_array = $searchandfilter->get(1446)->current_query()->get_array();
    echo '<pre>';
    print_r($sf_current_query_array);
    echo '</pre>';

    CHANGE THE ID NUMBER in the above code (1446) to whatever the ID of you form is.

    You will then see the array of filters used, and you can figure than how to fetch the value you need to add PHP to your template to test what the user has selected.

    #180060

    In reply to: Search results for ""


    Anonymous
    Inactive

    Hi Trevor,

    Thanks for your help with this. It looks like the code I need to use is:

    Get the Search Term
    <?php
    //Get the search term
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1526)->current_query();
    echo $sf_current_query->get_search_term();
    ?>

    However, I’m not clear where I should be inserting this in the theme – should I be looking for the search.php template file and inserting it in there where the searched terms are shown?

    Thanks,

    Matthew

    #179658

    Trevor
    Participant

    You would need to be using our Shortcode Display results method, and have followed the guide to customising:

    https://support.searchandfilter.com/documentation/search-filter-pro/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(1024)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // the results.php PHP code here
    }

    Make sure you change the ID number in that snippet to the ID number of your form.

    #178123

    In reply to: Get Count of Filters


    Trevor
    Participant

    Please note that, as your license has expired, you will first need to renew at the (discounted) renewal price to receive support.

    Does this code show anything different?

    $sf_current_query_array = $searchandfilter->get(1446)->current_query()->get_array();
    echo '<pre>';
    print_r($sf_current_query_array);
    echo '</pre>';

    You will need to change the ID number of course. There are some threads on the forum that you can search for where other users have used this code to access the filters data.

    #177706

    Trevor
    Participant

    With our Shortcode method, in the documentation link I gave you, is the guide to customising.

    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(1024)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // the results.php PHP code here
    }
    #176841

    Trevor
    Participant

    Are you using our shortcode display results method? If so, edit the results.php file to use code like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1024)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your template archive code/loop OR results.php code here
    }

    Change 1024 to the ID number of your form (from the form shortcode).

    Make sure you are working on a copy of the results.php file in a search-filter sub-folder of your theme/child theme folder, and not the original in our plugin template folder.

    #176709

    Anonymous
    Inactive

    That didn’t work but the one from the link you provided earlier did work.

    Here’s the code:

    global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(71131)->current_query();
    
    	$args = array(
    		"str" 					=> '%2$s', 
    		"delim" 				=> array(", ", " - "), 
    		"field_delim"				=> ', ', 
    		"show_all_if_empty"			=> false 
    	);
    	
    	$result_title = $sf_current_query->get_fields_html(
    		array("_sft_ld_course_category"), 
    		$args
    	);

    Thank you for your help with this.

    #176626

    Trevor
    Participant

    As you are if you are using our shortcode display results method (and therefore our results.php template file), it needs to be edited to look like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1024)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your template archive code/loop OR results.php code here
    }

    Change 1024 to the ID number of your form (from the form shortcode).

    Make sure you are working on a copy of the results.php file in a search-filter sub-folder of your theme/child theme folder, and not the original in our plugin template folder.

    #176590

    Trevor
    Participant

    Instead do this I think:

    <?php 
    $args = array(
      "str" => '%2$s',
      "show_all_if_empty" => false 
    );
    echo $sf_current_query->get_field_html(array("_sft_ld_course_category"),$args);
    ?>
    #176578

    Anonymous
    Inactive

    Follow up:

    The string that is returned for this:

    <?php echo $sf_current_query->get_field_string("_sft_ld_course_category"); ?>
    

    (ld_course_category is the course category for the learndash lms plugin)

    is:

    Course Categories: All Course Categories

    Is there a way the to get rid of the “Course Categories:” portion of the string so I’m just left with the actual result?

Viewing 10 results - 161 through 170 (of 318 total)