-
AuthorSearch Results
-
July 31, 2020 at 11:57 am #254714
In reply to: Results count
AnonymousInactiveTrevor,
I did try this:
$sf_current_query = $searchandfilter->get($id)->current_query();
$term = $sf_current_query->get_search_term();
$count = $sf_current_query->found_posts;I returns the term, but not the count. How can I get the results count from the Search and Filter query?
Thank you,
Christian
July 29, 2020 at 3:11 pm #254383In reply to: empty results by default
TrevorParticipantAre you using our Shortcode Display Results method. If not, you would need to be using a method that uses a (simple) theme PHP template and be abel to add code like this (the ID number needs to match your form):
global $searchandfilter; $sf_current_query = $searchandfilter->get(1234)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo '<div>Nothing to see here folks!</div>'; } else { // the current (filtered) posts output code here }
July 29, 2020 at 9:09 am #254268In reply to: Set default search order
TrevorParticipantSo, the logic would look something like this (the ID would match that of the search form):
global $searchandfilter; $sf_current_query = $searchandfilter->get(1234)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { // the code to display the 8-10 default houses } else { // the normal results loop code here }
But, I am not sure Avada uses traditional templates, so this may be difficult to code. In the past, other Avada users have needed to use a third party grid plugin, such as this method (which does not offer the option to do as you want in this case):
https://searchandfilter.com/documentation/3rd-party/post-grid/
July 17, 2020 at 9:56 am #253147In reply to: Show Dropdown Selection in Page Title
TrevorParticipantThe code you would need is:
global $searchandfilter; $sf_current_query = $searchandfilter->get(9490)->current_query()->get_array(); echo $sf_current_query['_sfm_UnitLocation']['active_terms'][0]['name'];
Look carefully, as only the ‘global’ line is the same.
Note, if you are using Ajax on the page, you may need to make sure that the page title is inside the Ajax Container, otherwise it will not refresh and change.
July 17, 2020 at 7:14 am #253140In reply to: Show Dropdown Selection in Page Title
AnonymousInactiveJust FYI, I have added this code within my #main container on the archive template. Nothing shows.
global $searchandfilter; $sf_current_query = $searchandfilter->get(9490)->current_query(); echo $sf_current_query->get_field_string("_sfm_UnitLocation");
July 14, 2020 at 11:47 am #252766
TrevorParticipantHaving said that, you might be able to do it using this filter:
https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object
… where the PHP would first have to check to see if a search has been done, and then conditionally remove the numbers in brackets from the labels. But that might slow things down a little.
The general method to detect if a search has been made is this:
global $searchandfilter; $sf_current_query = $searchandfilter->get(1234)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { // code here to remove the counts }
Replace the ID number with that of your form.
As the count is always in brackets, you could find the position of the last instance of
(
in the string, and trim the string to that left most number of characters of the string (minus 1 I think, as there will be a space also).July 10, 2020 at 10:36 am #252346
TrevorParticipantDoes that page use a PHP template file? If it does, using a child theme and a copy of that file in the child theme folder, edit that file to place logic like this in to it:
global $searchandfilter; $sf_current_query = $searchandfilter->get(1234)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo '<div>Nothing to see here folks!</div>'; } else { // the current products output code here }
The ID number must match that of your form.
Note, if you are using a page builder, this method may not be possible.
July 7, 2020 at 12:30 pm #251712
TrevorParticipantMore complex is needed then.
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1234)->current_query()->get_array(); $search_cat = $sf_current_query['_sft_category']['active_terms'][0]['name']; ?> <header class="searсh-header"> <h1 class="page-title">Résultats de la recherche : <span><?php echo $search_cat;?></span></h1></header>
July 7, 2020 at 12:18 pm #251704
TrevorParticipantAh, sorry, I just realized, you want the category to show, NOT the search term?
That may be a little more complex. This MIGHT work:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1234)->current_query(); $search_cat = $sf_current_query->get_field_string("_sft_category"); ?> <header class="searсh-header"> <h1 class="page-title">Résultats de la recherche : <span><?php echo $search_cat;?></span></h1></header>
July 7, 2020 at 11:57 am #251679
TrevorParticipantYou will need to replace 1234 with your form ID.
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1234)->current_query(); $search_term = $sf_current_query->get_search_term(); ?> <header class="searсh-header"> <h1 class="page-title">Résultats de la recherche : <span><?php echo $search_term;?></span></h1></header>
See if that works?
-
AuthorSearch Results