-
AuthorSearch Results
-
April 23, 2018 at 7:08 am #173724
In reply to: Select Box Like Ted
TrevorParticipantAssuming that
Post Type
is 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?
April 11, 2018 at 9:43 am #171426In reply to: hide results on initial page load
AnonymousInactiveI also tried what you wrote here:
https://support.searchandfilter.com/forums/topic/how-do-i-hide-initial-results/page/2/
addingif ( $query->have_posts() ) { global $searchandfilter; $sf_current_query = $searchandfilter->get(40276)->current_query(); if ($sf_current_query->is_filtered()) { ?>
to the results.php file but the results are now completely hidden – on the initial page load and they are not showing after the search.
March 30, 2018 at 5:23 pm #169245In reply to: Issue with get_fields_html
TrevorParticipantBut I don’t access it using get_fields_html. I do it like this:
global $searchandfilter; $sf_current_query = $searchandfilter->get(934)->current_query()->get_array(); $my_post_type = $sf_current_query[post_type][active_terms][0][value];
March 30, 2018 at 4:28 pm #169225In reply to: Issue with get_fields_html
AnonymousInactiveI’ve done that already, if you look at the bottom code in the original post.
So what you’re saying is that you can’t access it via $sf_current_query->get_fields_html(array(“_sf_s”, “_sft_access_level”, “post_type”,”_sft_topic”)); despite “post_type” being in there?
There’s not a lot of documentation on it so it’s difficult to know exactly what is to be expected here.
The https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/ page just has examples but doesn’t explain much.March 30, 2018 at 3:57 pm #169216In reply to: Issue with get_fields_html
AnonymousInactiveNo, I’m trying to get the post_type from $sf_current_query->get_fields_html(array(“_sf_s”, “_sft_access_level”, “post_type”,”_sft_topic”));
You can see it in the image under form_fields/post_type/post_types
Why are they not formatted in $sf_current_query->get_fields_html(array(“_sf_s”, “_sft_access_level”, “post_type”,”_sft_topic”)); as in the other array entries?
March 30, 2018 at 1:56 pm #169189In reply to: Accessing Field slug on search results
AnonymousInactiveI think I’ve sorted it thanks Trevor – sorry to mess you around!
If anyone else needs it, the code is as follows:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1446)->current_query(); $array_data = $sf_current_query->get_array(); $typeOfSearch = $array_data["_sft_pwb-brand"]["active_terms"][0]["value"]; echo $typeOfSearch ; ?>
Where _sft_pwb-brand is the field you need, and 1446 is the ID of the search form.
-
AuthorSearch Results