-
AuthorSearch Results
-
June 25, 2018 at 12:31 pm #181171
In reply to: Sort order – different query
TrevorParticipantYou 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.
June 8, 2018 at 2:20 pm #180060In reply to: Search results for ""
AnonymousInactiveHi 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
//replace1526
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
June 4, 2018 at 1:56 pm #179658In reply to: Show no results before making selections?
TrevorParticipantYou would need to be using our Shortcode Display results method, and have followed 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 }
Make sure you change the ID number in that snippet to the ID number of your form.
May 17, 2018 at 7:25 am #178123In reply to: Get Count of Filters
TrevorParticipantPlease 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.
May 15, 2018 at 5:20 pm #177706In reply to: Page Reset – Issues????
TrevorParticipantWith 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 }
May 10, 2018 at 2:11 pm #176841In reply to: Displaying results on load
TrevorParticipantAre 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.
May 9, 2018 at 5:03 pm #176709In reply to: How do display the category in results?
AnonymousInactiveThat 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.
May 9, 2018 at 10:12 am #176626In reply to: Hide results list by default
TrevorParticipantAs 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.
May 9, 2018 at 6:08 am #176590In reply to: How do display the category in results?
TrevorParticipantInstead 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); ?>
May 9, 2018 at 2:19 am #176578In reply to: How do display the category in results?
AnonymousInactiveFollow 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?
-
AuthorSearch Results