-
AuthorSearch Results
-
February 17, 2020 at 10:51 am #234043
In reply to: Only Show Results Once Submitted
TrevorParticipantYou would need to be using our Shortcode Display results method (as you are), and have followed the ‘guide to customising’:
Once you have a copy of the results.php file in a
search-filter
sub-folder of your theme, you can edit that file, like this (leave the PHP comments at the top outside and before this code):global $searchandfilter; $sf_current_query = $searchandfilter->get(1605)->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 resuts.php code here }
January 30, 2020 at 8:47 am #232565
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 temporarily use this code in your results template to display the full filter array so that you can work out the exact array part that holds the data you want:
<?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.
January 23, 2020 at 7:55 pm #231954In reply to: Get the Search value name inside result loop
TrevorParticipantThe currently applied filters are accessible to PHP. You would need the help of a skilled third party PHP coder, I think, to modify the template code for the results loop.
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.
January 23, 2020 at 1:55 pm #231924In reply to: Display selected category in WordPress template
TrevorParticipantThe currently applied filters are accessible to PHP. You would need the help of a skilled third party PHP coder, I think.
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.
January 22, 2020 at 12:26 pm #231823In reply to: Hide Posts if nothing is selected, then show them
AnonymousInactiveHere is my code, just replace the <?php the_title (); ?> with your code (thumbnail, tags, categories..) and there you go.
<?php /** * Search & Filter Pro * * Sample Results Template * * @package Search_Filter * @author Ross Morsali * @link http://www.designsandcode.com/ * @copyright 2015 Designs & Code * * 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 * */ global $searchandfilter; $sf_current_query = $searchandfilter->get(5555)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { ?> <?php // set up or arguments for our custom query $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $query_args = array( 'post_type' => 'renting', 'post__not_in' => array(4894, 4898, 4900, 4902, 4896), 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'mostrar-en-parrilla', 'field' => 'slug', 'terms' => 'si', ), ), 'posts_per_page' => -1, 'paged' => $paged ); // create a new instance of WP_Query $the_query = new WP_Query( $query_args ); ?> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // run the loop ?> <?php the_title (); ?> <?php endwhile; ?> <?php endif; ?> <?php wp_reset_query(); ?> <?php } else { 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(); ?> <?php the_title (); ?> <?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"; } } ?>
January 21, 2020 at 4:58 pm #231741In reply to: Hide Posts if nothing is selected, then show them
TrevorParticipantDid you use other templates as a basis for example code? The problem I face is that the code you showed me does not have a good structure.
At the least it should look like this, with no wp_query or arguments inside this code, they should go first:
`<?php
// arguments and wp_query here
global $searchandfilter;
$sf_current_query = $searchandfilter->get(2611)->current_query();
if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==””)) {
echo ‘<div>Nothing to see here folks!</div>’;
} else {
if ( $query->have_posts() )
{
?><?php
while ($query->have_posts())
{
$query->the_post();
// output the post here
}}
else
{
echo “<span id=’no-results’>No results found, please try altering your search criteria.</span>”;
}
}
?>But, for example, you have wp_query being run twice, two sets of arguments, and starting if have_posts twice?
January 21, 2020 at 4:16 pm #231727In reply to: Hide Posts if nothing is selected, then show them
AnonymousInactiveI tried to modify the filter i’ve got working on my home page but with results. On my home the filter hides any results before the user select an option and press the submit button.
and the code was the one I gave you before:
<?php echo do_shortcode ('[searchandfilter id="2611"]'); ?> <div class="filtro-cars" data-wow-duration="1s" data-wow-delay="0.3s"> <?php global $searchandfilter; $sf_current_query = $searchandfilter->get(2611)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo ''; } else { ?> <?php $args = array('post_type' => 'renting'); $args['search_filter_id'] = 2611; $query = new WP_Query($args);?> <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); // run the loop ?> <?php the_title (''); ?> <?php endwhile; else: ?> <div class="no-results">No hemos encontrado resultados, prueba con otros criterios de búsqueda.</div> <?php endif; ?> <?php wp_reset_query(); ?> <?php } ?> </div>
Maybe I need to start all over again, I need a page with all the results of a query of custom post (excluding some posts by ID) and then when the user use the filter the results must show by ajax.
🙂
January 21, 2020 at 4:00 pm #231715In reply to: Hide Posts if nothing is selected, then show them
AnonymousInactiveThis is a page that I’m using for the filter, but I needed to have results before the user uses the filter, that’s why I opened the other post asking for help.
This is the code I’ve got before:
<?php echo do_shortcode ('[searchandfilter id="2611"]'); ?> <div class="filtro-cars" data-wow-duration="1s" data-wow-delay="0.3s"> <?php global $searchandfilter; $sf_current_query = $searchandfilter->get(2611)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo ''; } else { ?> <?php $args = array('post_type' => 'renting'); $args['search_filter_id'] = 2611; $query = new WP_Query($args);?> <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); // run the loop ?> <?php the_title (''); ?> <?php endwhile; else: ?> <div class="no-results">No hemos encontrado resultados, prueba con otros criterios de búsqueda.</div> <?php endif; ?> <?php wp_reset_query(); ?> <?php } ?> </div>
January 17, 2020 at 2:45 pm #231466In reply to: Check events pagination page number
AnonymousInactiveI tried like this:
$sf_current_query = $searchandfilter->get(334)->current_query(); print_r($sf_current_query->get_query_var('paged'));
but I have an error…
January 17, 2020 at 1:46 pm #231454In reply to: Check events pagination page number
TrevorParticipantDoes it appear if you edit the template and add this code:
$sf_current_query = $searchandfilter->get(334)->current_query(); echo '<pre>'; print_r($sf_current_query->get_array()); echo '</pre>';
(this will print an array to the page)
-
AuthorSearch Results