-
AuthorSearch Results
-
December 11, 2018 at 12:57 pm #195882
In reply to: Results initially added via AJAX
AnonymousInactiveHey,
I’m using PHP, so if this is the query:
$sf_current_query = $searchandfilter->get(1033)->current_query();
Once I have $sf_current_query how do I feed that into wp_query to return a specific set of results?
Thanks,
DanNovember 9, 2018 at 3:36 pm #193405In reply to: Show relationship ACF field in results
TrevorParticipantYes, like this:
global $searchandfilter; $sf_current_query = $searchandfilter->get(12204)->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 }
October 31, 2018 at 6:14 pm #192425In reply to: Checkboxen uncheck after ajax refresh
AnonymousInactiveThanks for the links about this subject and great to hear about this option coming to the plugin in 2019.
In this guide: https://searchandfilter.com/documentation/accessing-search-data/
I have to use a code and replace it with the form-id. But I have 9 different forms, using the same page-template, who are switched on and off by some widget logic.
Is their a possibility to use this code and let the code search for the right for id who is active on the page the user is visiting?:<?php //Get a single fields values using labels //replace <code>1526</code> with the ID of your search form global $searchandfilter; $sf_current_query = $searchandfilter->get(1526)->current_query(); echo $sf_current_query->get_field_string("_sft_category"); ?>
October 31, 2018 at 5:53 pm #192423In reply to: Checkboxen uncheck after ajax refresh
TrevorParticipantThis 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/
October 30, 2018 at 6:33 pm #192218In reply to: Search results
TrevorParticipantAh, I can see what you have done now. It would need for part of the blog page template to be placed in the results.php file and for the blog template instead of calling the results shortcode, to call the content.
I can write this for you if you want:
In blog-page.php change lines 24-29:
<div class="page-blog page-blog-title">Recent posts</div> <div class="blog-posts"> <?php echo do_shortcode('[searchandfilter id="463" show="results"]');?> </div> </div>
with:
<?php the_content(); ?>
Next, in the results.php file, find lines 68 and 69:
</a></a> </div>
I believe these have errors and should be just:
</a>
At the very end of the file is a blank line, after this:
else ?> <?php { } ?>
Here add two closing tags:
</div> </div>
Now find lines 25 and 26 (which are blank) and paste these lines:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(463)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { $page_title = "Recent Posts"; } else { $page_title = "Search results for: " . $sf_current_query->get_search_term(); }?> <div class="page-blog page-blog-title">Recent posts</div> <div class="blog-posts">
I think that will do as you want. The title must be inside the results.php for it to be affected by if there are results.
October 30, 2018 at 1:50 pm #192127In reply to: Search results
TrevorParticipantThe text that says Recent post is what that line I highlighted makes. In any event that lines needs to be this instead, I think (try it):
<div class="blog-post__title"><?php the_title();?></div>
So, you would now need to find out if the page is filtered, like this, where the last line replaces line 42:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1024)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { $page_title = the_title(); } else { $page_title = "Search results for: " . $sf_current_query->get_search_term(); }?> <div class="blog-post__title"><?php echo $page_title;?></div>
Note that this only shows the text search term. If you want fields choices, taxonomy choices, it becomes more complicated, which is what that documentation page shows how to do..
October 29, 2018 at 10:54 am #191996
TrevorParticipantAs you are using the WooCommerce method to display results, it is your theme and/or WooCommerce that controls the output of the HTML and results. If you have access to the PHP template file being used, this PHP will generally detect if a search has been made or not:
global $searchandfilter; $sf_current_query = $searchandfilter->get(20549)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { // your template archive code to show when there is search yet } else { // your template archive code to show search results }
October 19, 2018 at 12:19 pm #191321In reply to: Stop loading results on page load
TrevorParticipantAs you are using the Shortcode results method, and our results.php template file (infinite scroll version), 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).
October 16, 2018 at 12:31 pm #191069In reply to: Echo the query/search term
TrevorParticipantDo you have this bit:
echo $sf_current_query->get_search_term();
October 16, 2018 at 12:23 pm #191067In reply to: Echo the query/search term
AnonymousInactiveI don’t have any other filters, and the first link/example doesn’t seem to work.
<?php
//grab the active query from our search form
//replace1526
with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1445)->current_query();
?>This should grab the search term and output it on the page, right?
-
AuthorSearch Results