-
AuthorSearch Results
-
May 10, 2018 at 2:11 pm #176841
In 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 8, 2018 at 11:57 am #176320
TrevorParticipantThis would depend on the layout template being used for your page. That would depend on your theme or page builder/content plugin that you are using, or, if you are using our shortcode display results method and our results.php template file, it would 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).
May 7, 2018 at 11:22 am #176099
TrevorParticipantIt does indeed make sense. Here is how you would code what you want to do:
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).
April 23, 2018 at 7:08 am #173724In reply to: Select Box Like Ted
TrevorParticipantAssuming that
Post Typeis one of the search fields, it should work in exactly the same way. If it does not, you need to print out the entire search/filter array and examine the structure, like this:$sf_current_query_array = $searchandfilter->get(1446)->current_query()->get_array(); echo '<pre>'; print_r($sf_current_query_array); echo '</pre>';Change the ID accordingly for your form.
And then check to see if the terms you need are contained in that.
April 20, 2018 at 10:58 pm #173537In reply to: Updating search data via AJAX not returning anything
AnonymousInactiveOk, turns out I was way overengineering this. The simple solution is to put he PHP block INSIDE the element that the AJAX results load into. Like this:
<div id="ajax-results"> <?php global $searchandfilter; $sf_current_query = $searchandfilter->get(12192)->current_query(); echo $sf_current_query->get_fields_html( array("_sft_travelmonth","_sft_destination", "_sft_activities"), $args ); ?>April 12, 2018 at 11:07 pm #171986In reply to: Display multiple terms
AnonymousInactiveTrevor, thanks again for spending time with me today. I really appreciated it.
Good news, I finally figured it out!
Here’s the happy code:
<?php global $searchandfilter; $args = array( "str" => '%2$s', "delim" => array(", ", " - "), "field_delim" => ', ', "show_all_if_empty" => false ); $sf_current_query = $searchandfilter->get(99801)->current_query()->get_array(); $sf_current_style_query = $searchandfilter->get(99801)->current_query()->get_fields_html(array("_sft_style", "_sft_name"),$args); $sf_current_cuisine_query = $searchandfilter->get(99801)->current_query()->get_fields_html(array("_sft_cuisine", "_sft_name"),$args); echo '<strong>Filters</strong>'; if ( empty($sf_current_query ) ) { echo ' • ' . "All" . "<br /><br />"; } else { echo ' • ' . $sf_current_query['_sft_category']['active_terms'][0]['name'] . ' • ' . $sf_current_query['_sfm_wpcf-location-city']['active_terms'][0]['name'] . ' • ' . $sf_current_style_query . ' • ' . $sf_current_cuisine_query; echo "<br /><br />"; } ?>Cheers!
April 12, 2018 at 4:34 am #171733In reply to: Display multiple terms
AnonymousInactiveOkay, good news, I’m making progress…
This works for the array:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(99801)->current_query(); if ( empty($sf_current_query ) ) { echo '<strong>Filters</strong>' . ' • ' . "All" . "<br /><br />"; } else { $args = array( "str" => '%2$s', "delim" => array(", ", " - "), "field_delim" => ', ', "show_all_if_empty" => false ); echo '<strong>Filters</strong>' . ' • ' . $sf_current_query->get_fields_html(array("_sft_cuisine", "_sft_name"), $args); } echo '<br />'; ?>Now I need to pull in the $key[‘active_terms’][0][‘name’] from the original code (it will display before the array).
That will give me what I’m after…
Filters • Florida • Caribbean, MexicanHow do I combine it?
April 11, 2018 at 8:57 pm #171651In reply to: Display multiple terms
TrevorParticipantYou are correct. You need to examine the data structure of the filter array and then, where multiple values are permitted, use a loop to output them.
You can print the filter array to screen with code like this:
$sf_current_query = $searchandfilter->get(1446)->current_query(); echo '<pre>'; print_r($sf_current_query->get_array()); echo '</pre>';But then it is a matter of coding it in PHP. I cannot see an example code snippet on our forum though. I would have thought it possible to replace echo with explode where you are handling an array?
-
AuthorSearch Results