-
AuthorSearch Results
-
February 11, 2017 at 11:45 pm #89576
In reply to: Post Meta Date Range
AnonymousInactiveThank for your answer. Do you have a code sample? I tried some but no result.
function filter_function_name( $query_args, $sfid ) { if( $sfid == 940 ) { global $searchandfilter; $sf_current_query = $searchandfilter->get(940)->current_query(); $array_data = $sf_current_query->get_array(); $tender_start = $array_data['_sfm_tender_start']['active_terms'][0]['value']; $tender_end = $array_data['_sfm_tender_end']['active_terms'][0]['value']; $args = array( 'meta_key' => 'tender_start', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'tender_start', 'compare' => '>=', 'value' => $tender_start ), array( 'key' => 'tender_end', 'compare' => '<=', 'value' => $tender_end ) ) ); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
February 2, 2017 at 5:25 pm #87657In reply to: Force selection?
TrevorParticipantHi Lisa
You can also let them search, but show them nothing (or a custom message) using this type of PHP code (change the number
1234
for the ID number of your search form and change the lineecho '<div>Nothing to see here folks!</div>';
for whatever you want before the filter is used instead of the results – or remove for nothing at all):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 { // your theme template code here for the part that runs the loop, e.g. if ( $query->have_posts() ) ..... }
For example, if you were using the shortcode method. OK, if you have followed the documentation to make a copy of the results.php into a new folder called
search-filter
in your child theme or theme folder, then replace the contents of that template file with this:<?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(1234)->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() ) { ?> 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><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></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"; } } ?>
January 26, 2017 at 2:55 pm #85731
TrevorParticipantJust in case this happens again, this is the code I wrote:
<?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(5048)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo ''; } 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> <div class="slz-shortcode sc_block_posts "><div class="slz-template-03 "> <div class="slz-list-block slz-column-2"> <?php while ($query->have_posts()) { $query->the_post(); ?> <div class="item"> <div class="slz-block-item-01 style-1"> <?php if ( has_post_thumbnail() ) {?> <div class="block-image"> <a href="<?php the_permalink(); ?>" class="link"> <?php the_post_thumbnail("full", array( 'class' => 'img-responsive' ));?> </a> </div> <?php } ?> <div class="block-content"> <div class="block-content-wrapper"> <a class="block-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <ul class="block-info"> <li><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"><span class="author-label">By </span><span class="author-text"><?php the_author(); ?></span></a></li> <li><a href="<?php the_permalink(); ?>" class="link date"><?php the_date(); ?></a></li> <li><a href="<?php the_permalink(); ?>#comments" class="link comment"><?php comments_number();?></a></li> <li><a href="<?php the_permalink(); ?>" class="link view">?? Views</a> </li> <li><?php the_category(); ?></li> </ul> <div class="block-text"><?php echo get_the_excerpt(); ?></div> </div> </div> </div> </div> <?php } ?> </div> </div></div> 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 17, 2017 at 7:35 pm #83207In reply to: Taxonomy filter not working 2.3
AnonymousInactiveoh and again
global $searchandfilter; $sf_current_query = $searchandfilter->get(1530)->current_query();
doesnt return anything when selecting parent taxonomy, only when selecting taxonomy post is assigned to.
January 5, 2017 at 10:28 am #80210
TrevorParticipantThere were a couple of errors in that, so I have re-coded it (I am not sure about the do_shortcode bit, but I have left that as is):
<?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(3552)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo "make your selection"; } else { if ( $query->have_posts() ) { echo '<div class="row">'; while ($query->have_posts()) { $query->the_post(); ?> <div class="col-md-3 popmake-<?php the_ID();?>" data-do-default="" style="cursor: pointer;"> <h3 style="text-align: center;"><?php the_title(); ?></h3> <p style="text-align: center;"><?php do_shortcode(the_excerpt()); ?></p> </div> <?php echo '</div>'; } } else { echo 'No Results Found'; } } ?>
That may make no difference, but give it a try.
January 5, 2017 at 10:20 am #80206
AnonymousInactiveshure!
<?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(3552)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo "make your selection"; } else { if ( $query->have_posts() ) { echo "<div class=\"row\">"; while ($query->have_posts()) { $query->the_post(); ?> <div class="col-md-3 popmake-<?php the_ID();?> data-do-default="" style="cursor: pointer;"> <h3 style="text-align: center;"><?php the_title(); ?></h3> <p style="text-align: center;"><?php do_shortcode(the_excerpt()); ?></p> </div> <?php echo "</div>"; } } else { echo "No Results Found"; } } ?>
December 30, 2016 at 4:43 pm #79288
TrevorParticipantMarjan, we seem to have successfully coded up the solution for this, using a PHP snippet:
<?php global $searchandfilter; $sf_query = $searchandfilter->get(3217)->current_query(); if ($sf_query->is_filtered()) { $sf_current_query = $searchandfilter->get(3217)->current_query()->get_array(); echo "<b>Prikaz rezultatov za...</b>"; $cat_string = ""; foreach($sf_current_query['_sft_category']['active_terms'] as $item) { $cat_string .= $item['name'] . ", "; } $starost_string = ""; foreach($sf_current_query['_sfm_starost']['active_terms'] as $item) { $starost_string .= $item['name'] . ", "; } if (($sf_current_query['_sft_category']['active_terms'][0]['name'])<>"") echo "<div>PRODUKTI: " . substr($cat_string, 0, -2) . "</div>"; if (($sf_current_query['_sft_post_tag']['active_terms'][0]['name'])<>"") echo "<div>STANJA: " . ($sf_current_query['_sft_post_tag']['active_terms'][0]['name']) . "</div>"; if (($sf_current_query['_sfm_kakovost_spremembe']['active_terms'][0]['name'])<>"") echo "<div>KAKOVOST SPREMEMBE: " . ($sf_current_query['_sfm_kakovost_spremembe']['active_terms'][0]['name']) . "</div>"; if (($sf_current_query['_sfm_starost']['active_terms'][0]['name'])<>"") echo "<div>STAROST: " . substr($starost_string, 0, -2) . "</div>"; if (($sf_current_query['_sfm_vrsta_primera']['active_terms'][0]['name'])<>"") echo "<div>VRSTA PRIMERA: " . ($sf_current_query['_sfm_vrsta_primera']['active_terms'][0]['name']) . "</div>"; } ?>
So I will close this now. Great to speak with you on Skype.
December 29, 2016 at 7:49 pm #79193
TrevorParticipantOK, if you have followed the documentation to make a copy of the results.php into a new folder called
search-filter
in your child theme or theme folder, then replace the contents of that template file with this (change the number255
for the ID number of your search form and change the lineecho '<div>Nothing to see here folks!</div>';
for whatever you want before the filter is used instead of the results – or remove for nothing at all):<?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(255)->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() ) { ?> 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><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></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"; } } ?>
December 17, 2016 at 9:13 am #77226
TrevorParticipantOK, nearly there. This is the code we have so far:
<?php global $searchandfilter; $sf_query = $searchandfilter->get(3217)->current_query(); if ($sf_query->is_filtered()) { ?> <div>Found <?php echo $sf_query->found_posts; ?> Results</div> <?php $sf_current_query = $searchandfilter->get(3217)->current_query()->get_array(); if (($sf_current_query['_sft_category']['active_terms'][0]['name'])<>"") echo "<div>KATEGORIJE: " . ($sf_current_query['_sft_category']['active_terms'][0]['name']) . "</div>"; if (($sf_current_query['_sft_post_tag']['active_terms'][0]['name'])<>"") echo "<div>OZNAKE: " . ($sf_current_query['_sft_post_tag']['active_terms'][0]['name']) . "</div>"; if (($sf_current_query['_sfm_kakovost_spremembe']['active_terms'][0]['name'])<>"") echo "<div>KAKOVOST SPREMEMBE: " . ($sf_current_query['_sfm_kakovost_spremembe']['active_terms'][0]['name']) . "</div>"; if (($sf_current_query['_sfm_starost']['active_terms'][0]['name'])<>"") echo "<div>STAROST: " . ($sf_current_query['_sfm_starost']['active_terms'][0]['name']) . "</div>"; if (($sf_current_query['_sfm_vrsta_primera']['active_terms'][0]['name'])<>"") echo "<div>VRSTA PRIMERA: " . ($sf_current_query['_sfm_vrsta_primera']['active_terms'][0]['name']) . "</div>"; } ?>
And we know that the only part NOT working is:
<div>Found <?php echo $sf_query->found_posts; ?> Results</div>
December 4, 2016 at 6:26 pm #73970In reply to: How to output the type of search done
AnonymousInactiveHey Trevor,
Managed to figure it out.
For the record here’s what I used (replacing 725 with whatever your specific search ID is..)
<?php
global $searchandfilter;
$sf_current_query = $searchandfilter->get(725)->current_query();$array_data = $sf_current_query->get_array();
$typeOfSearch = $array_data[“_sf_sort_order”][“active_terms”][0][“value”];echo $typeOfSearch ;
?>
Keith
-
AuthorSearch Results