-
AuthorSearch Results
-
July 9, 2019 at 11:16 am #215764
TrevorParticipantThe ‘As an Archive’ method might cause that to happen
add_action('pre_get_posts', 'myprefix_query_offset', 1 ); function myprefix_query_offset(&$query) { if (is_front_page() && $query->is_main_query()){ global $searchandfilter; $sf_current_query = $searchandfilter->get(12345)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { return; } else { // RUN CODE ONLY ON FRONT PAGE AND MAIN QUERY } } }That might work. Change 12345 for the ID of your form.
July 5, 2019 at 4:04 pm #215649
TrevorParticipantTo fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:
https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/
… and this search will give similar threads I think:
https://support.searchandfilter.com/forums/search/sf_current_query+get_array
Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.
You could use this to display the filter array:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array(); echo '<pre>',print_r($sf_current_query,true),'</pre>'; ?>Where the ID needs to match that of your form.
July 1, 2019 at 8:43 am #215288In reply to: get selected value and show on page?
TrevorParticipantI am not sure if this is what you want. To show the filters, as I said, this requires custom coding when using the current version of Search & Filter Pro. You can access the filter terms though, but would need further PHP work to display them. To fetch the search terms, the
https://searchandfilter.com/documentation/accessing-search-data/
guide is basic but you can extend the idea to fetch other filter terms/data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:
https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/
… and this search will give similar threads I think:
https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/
Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.
June 6, 2019 at 1:52 am #213402In reply to: i want to get the current sfid
AnonymousInactivei use the shortcode to display my result, and in the shortcode I use the next code
$sf_current_query = $searchandfilter->get( 1391 )->current_query();
theget( 1391 )is fixed ID….i need something like
$sf_current_query = $searchandfilter->get( $sfid )->current_query();June 5, 2019 at 9:27 am #213328In reply to: i want to get the current active filter sort label
TrevorParticipantYou can find more details from the filter query array.
You may need to temporarily output the array to see how to access the term that you want.
If you add this code to the page, it will output the entire array:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array(); echo '<pre>',print_r($sf_current_query,true),'</pre>'; ?>June 5, 2019 at 7:46 am #213325
AnonymousInactiveI want to get the currently active filter sort label
I try this
global $searchandfilter; $sf_current_query = $searchandfilter->get(1391)->current_query(); $array_data = $sf_current_query->get_array(); $typeOfSearch = $array_data["_sf_sort_order"]["active_terms"][0]["value"];but I can’t get the label…
May 29, 2019 at 10:12 am #212706
TrevorParticipantIf I understand you correctly, you need to output the currently searched for term(s) on the results page. To an extent, this is limited by how the page is constructed, but as long as you have a PHP template and know how to edit/code that, you should be able to achieve what you want.
To show the filters, as I said, this requires custom coding when using the current version of Search & Filter Pro. You can access the filter terms though, but would need further PHP work to display them. To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:
https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/
… and this search will give similar threads I think:
https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/
Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.
May 22, 2019 at 10:48 am #211977
AnonymousInactiveHi.
OK so originally i had the Search & Filter (none pro ) version installed, so i have just installed the Pro version and started to set up the first form, using all the options etc.On the General Tab I set it to my ‘Lab Test’ custom posts.
Display Results i set it to ‘Post Type Archive’, but i can change that back to ‘Using A Shortcode’ if that is easier? And then on my Archive page add the code you suggested?
My current code is simply this (when i used the none pro version)
<div class=”search”><?php echo do_shortcode( ‘[searchandfilter fields=”search” search_placeholder=”Enter a Batch No” submit_label=”Search” post_types=”,labtests”]’ ); ?></div>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div><?php the_title(); ?></div>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>So should it be set to Use Shortcode, then change the code like this:
<?php
global $searchandfilter;
$sf_current_query = $searchandfilter->get(284)->current_query();
if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==””)) {
echo ‘<div>Nothing to see here folks!</div>’;
} else {
if (have_posts()) : while (have_posts()) : the_post();
}?>
May 22, 2019 at 10:23 am #211969
TrevorParticipantI need to know if you have this set as shown here:
https://www.screencast.com/t/jVW9z2FJ
If it is, then the results.php needs to be modified like this (where I have used the ID number of your form):
global $searchandfilter; $sf_current_query = $searchandfilter->get(85204)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo '<div>Nothing to see here folks!</div>'; } else { // your current results.php code here }Make sure any files you modify are in the child theme folder (if you copy our results.php file, it needs to be in a sub-folder of the child theme, called search-filter, not our plugin folder or a parent theme folder). Do NOT edit the copy of results.php that is in our plugin templates folder, as it will be overwritten by updates.
May 21, 2019 at 3:46 pm #211828In reply to: Check to see if anything has been searched
TrevorParticipantThe third line would be:
if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {So the first do something is if nothing has been searched.
-
AuthorSearch Results
Search Results for 'current_query'
-
Search Results
-
I want to get the currently active filter sort label
I try this
global $searchandfilter; $sf_current_query = $searchandfilter->get(1391)->current_query(); $array_data = $sf_current_query->get_array(); $typeOfSearch = $array_data["_sf_sort_order"]["active_terms"][0]["value"];but I can’t get the label…