-
AuthorSearch Results
-
April 16, 2019 at 9:40 am #208462
In reply to: Post Meta display current filter
TrevorParticipantYou 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.
April 15, 2019 at 11:44 pm #208449In reply to: show results only after clicking search
AnonymousInactiveHere I have to add something, I have several pages and in each one I use a different personalized filter, each page corresponds to a department of Colombia, therefore, what we are looking for, is that the search result only brings results from that department, that’s why, if you go to the next two pages, you can see that the filter results are different.
https://www.starpets.com.co/antioquia/
https://www.starpets.com.co/cundinamarca/This I clarify, since after reviewing the help forum, I found this answer that you gave previously to a user https://support.searchandfilter.com/forums/topic/prevent-empty-search-fetching-results/#post -185868 but I do not know if it applies to my project, since here you indicate that you should replace the id of the page, but if there are several forms and each one has a different id, how can I achieve what you indicate?
and so the code of my results.php file is displayed:
<?php /** * Search & Filter Pro * * Sample Results Template * * @package Search_Filter * @author Ross Morsali * @link https://searchandfilter.com * @copyright 2018 Search & Filter * * Note: these templates are not full page templates, rather * just an encaspulation of the your results loop which should * be inserted in to other pages by using a shortcode – think * of it as a template part * * This template is an absolute base example showing you what * you can do, for more customisation see the WordPress docs * and using template tags – * * http://codex.wordpress.org/Template_Tags * */ if ( $query->have_posts() ) { ?> Found <?php echo $query->found_posts; ?> Results<br /> Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br /> <div class="pagination"> <div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div> <div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div> <?php /* example code for using the wp_pagenavi plugin */ if (function_exists('wp_pagenavi')) { echo "<br />"; wp_pagenavi( array( 'query' => $query ) ); } ?> </div> <?php while ($query->have_posts()) { $query->the_post(); ?> <div> <h2>"><?php the_title(); ?></h2> <p><br /><?php the_excerpt(); ?></p> <?php if ( has_post_thumbnail() ) { echo '<p>'; the_post_thumbnail("small"); echo '</p>'; } ?> <p><?php the_category(); ?></p> <p><?php the_tags(); ?></p> <p><small><?php the_date(); ?></small></p> </div> <hr /> <?php } ?> Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br /> <div class="pagination"> <div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div> <div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div> <?php /* example code for using the wp_pagenavi plugin */ if (function_exists('wp_pagenavi')) { echo "<br />"; wp_pagenavi( array( 'query' => $query ) ); } ?> </div> <?php } else { echo "No Results Found"; } ?>
I do not know if there is something wrong here too, because in the page where I’m trying to find the code, at the end of the results, this comes out:
global $searchandfilter; $sf_current_query = $searchandfilter->get(2101)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==””)) { echo ‘
Nothing to see here folks!
‘; } else { // your template archive code/loop OR results.php code here }April 15, 2019 at 4:21 pm #208435Topic: Post Meta display current filter
in forum Search & Filter Pro
AnonymousInactiveHi there,
I’d like to display the name of the active Post Meta filter. I’ll be using this to show a message when nothing in this type is available, e.g. “We currently have no “freelance” jobs available”.
I have to note that I’m not working with any taxonomies, but rather have a Post Meta filter which I grab from advanced custom field values (which works like a charm, love the support).
I tried this code but unfortunately nothing shows up:
<?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(1860)->current_query(); echo $sf_current_query->get_field_string("_sft_verhouding"); ?>
You can check the page out here. Please note it’s already sorted on “Alphahulp”
March 30, 2019 at 3:42 pm #207000In reply to: No Results – DateTime Range
AnonymousInactiveI’ve made some progress with this.
I can alter the query by adjusting the meta_query as above but I need to remove a fields value from $sf_current_query. When I unset it the query is still run like it’s there.
I removed it like this
unset($sf_current_query['_sfm__audiotheme_gig_datetime']);
March 29, 2019 at 4:56 pm #206924In reply to: Hook to display number of filtered results?
TrevorParticipantThere is not, sorry. 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.
March 11, 2019 at 1:55 pm #204644In reply to: no terms are showing in dropdown fields
TrevorParticipantTo hide first results.
You now have a block of code in the results.php file (Ignoring the initial comments).
You need to add/wrap some code around the code you have, like this:
global $searchandfilter; $sf_current_query = $searchandfilter->get(36613)->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 }
… where the ID number will need to be changed to match your form ID
March 7, 2019 at 3:33 pm #204268
TrevorParticipantThe basic PHP for a ‘blank’ before search page is this:
global $searchandfilter; $sf_current_query = $searchandfilter->get(36613)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { // just your search form here } else { // your current template code here }
… where the ID number will need to be changed to match your form ID.
March 5, 2019 at 11:59 am #203951In reply to: Hide results by default
TrevorParticipantThe hide results code is like this:
global $searchandfilter; $sf_current_query = $searchandfilter->get(36613)->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 }
… where the ID number will need to be changed to match your form ID
February 13, 2019 at 2:53 pm #202121In reply to: results display
TrevorParticipantIf you are using our Shortcode Display Results method, then the results.php needs to be modified like this (where the ID number will need to be changed to match your form ID):
global $searchandfilter; $sf_current_query = $searchandfilter->get(36613)->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 }
If using other methods, and if you have access to the template PHP files, you could use similar code.
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).February 6, 2019 at 8:08 am #201347In reply to: Current menu item
TrevorParticipantYes, that is totally possible. You need to edit the results.php template file you are using, like this:
global $searchandfilter; $sf_current_query = $searchandfilter->get(36613)->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 }
-
AuthorSearch Results
-
Search Results
-
Hi there,
I’d like to display the name of the active Post Meta filter. I’ll be using this to show a message when nothing in this type is available, e.g. “We currently have no “freelance” jobs available”.
I have to note that I’m not working with any taxonomies, but rather have a Post Meta filter which I grab from advanced custom field values (which works like a charm, love the support).
I tried this code but unfortunately nothing shows up:
<?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(1860)->current_query(); echo $sf_current_query->get_field_string("_sft_verhouding"); ?>
You can check the page out here. Please note it’s already sorted on “Alphahulp”