-
AuthorSearch Results
-
May 6, 2016 at 6:41 pm #44951
In reply to: How do I hide initial results?
TrevorParticipantSo, it is relatively simple if you are using the Shortcode Display Results method. See the documentation:
http://www.designsandcode.com/documentation/search-filter-pro/search-results/using-a-shortcode/
See how it is using a template called results.php?
This is that file:
<?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 * */ 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"; } ?>
And here is it modified:
<?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 * */ if ( $query->have_posts() ) { global $searchandfilter; $sf_current_query = $searchandfilter->get(1526)->current_query(); if ($sf_current_query->is_filtered()) { ?> 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"; } ?>
replace 1526 with the id of your search form.
April 26, 2016 at 10:44 am #43915In reply to: How to style the search data
TrevorParticipantOk.
So, this is the code I made:
global $searchandfilter; $sf_current_query = $searchandfilter->get(339)->current_query()->get_array(); foreach($sf_current_query as $key) { echo '<div>' . $key['active_terms'][0]['name'] . '</div>'; }
If you wanted to put the X before each, replace the echo line with something like this:
echo '<div><a id="executeMyCodeLink" href="#">X</a> ' . $key['active_terms'][0]['value'] . '</div>';
Where the code to add to the page would be something like this
<script> $('#executeMyCodeLink').click(function(event) { /// Your code here }); </script>
But that is beyond the scope of what I can do easily 🙁
April 26, 2016 at 6:44 am #43893In reply to: How do I hide initial results?
TrevorParticipantSo, one error on the page 🙁
Line 26 should be this:
if ( !$sf_current_query->is_filtered() ) {
April 22, 2016 at 11:01 am #43630In reply to: How to style the search data
AnonymousInactiveThanks for this code, I had to adjust the code to add extra closing brackets for the STRING (below), unfortunately this results in the same data being given.
“Yacht Length: 40-50m”
<?php
global $searchandfilter;
$sf_current_query = $searchandfilter->get(339)->current_query();
echo $sf_current_query->get_field_string(“_sft_length”, array(“str” => “%2$s”));
echo $sf_current_query->get_field_string(“_sft_rate”, array(“str” => “%2$s”));
echo $sf_current_query->get_field_string(“_sft_guest”, array(“str” => “%2$s”));
echo $sf_current_query->get_field_string(“_sft_location”, array(“str” => “%2$s”));
echo $sf_current_query->get_field_string(“_sft_toy”, array(“str” => “%2$s”));
?>April 22, 2016 at 10:44 am #43625In reply to: How to style the search data
TrevorParticipantHi, can you try this code (it might be a step backwards, but bear with me):
global $searchandfilter; $sf_current_query = $searchandfilter->get(339)->current_query(); echo $sf_current_query->get_field_string("_sft_length", array("str" => "%2$s"); echo $sf_current_query->get_field_string("_sft_rate", array("str" => "%2$s"); echo $sf_current_query->get_field_string("_sft_guest", array("str" => "%2$s"); echo $sf_current_query->get_field_string("_sft_location", array("str" => "%2$s"); echo $sf_current_query->get_field_string("_sft_toy", array("str" => "%2$s");
April 21, 2016 at 5:04 pm #43565In reply to: How to style the search data
AnonymousInactiveHi,
I’ve added the code but it seems to be throwing an error on the array. Am I missing something?
<?php
//Get a multiple fields values by passing an array of field names
//replace1526
with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(339)->current_query();
echo $sf_current_query->get_fields_html(array(), array(‘show_all_if_empty’ => false)
);
?>I’ve also added the code from the supplied link but it throws back the following error:
array(2) { [“_sft_length”]=> array(5) { [“name”]=> string(13) “Yacht Lengths” [“singular_name”]=> string(12) “Yacht Length” [“all_items_label”]=> string(17) “All Yacht Lengths” [“type”]=> string(8) “taxonomy” [“active_terms”]=> array(1) { [0]=> array(4) { [“id”]=> int(6) [“name”]=> string(6) “40-50m” [“value”]=> string(6) “40-50m” [“count”]=> int(5) } } } [“_sft_toy”]=> array(5) { [“name”]=> string(15) “Yacht Hero Toys” [“singular_name”]=> string(14) “Yacht Hero Toy” [“all_items_label”]=> string(19) “All Yacht Hero Toys” [“type”]=> string(8) “taxonomy” [“active_terms”]=> array(1) { [0]=> array(4) { [“id”]=> int(16) [“name”]=> string(7) “Freezer” [“value”]=> string(7) “freezer” [“count”]=> int(5) } } } }Found on the same web link as before.
April 15, 2016 at 11:34 am #42840In reply to: Start filter search with no preloaded results.
TrevorParticipantHi
It should look like this a bit, I think:
global $searchandfilter; $sf_current_query = $searchandfilter->get(1726)->current_query(); if ($sf_current_query->is_filtered()) { // do the loop } else { // do something else }
April 14, 2016 at 2:32 pm #42786In reply to: Start filter search with no preloaded results.
AnonymousInactiveThanks Trevor!
I am using a theme I started from underscores templateInstalled the results.php template and I am trying to use the github code here as reference.
but no luck yet..Any chance you can guide me a bit further?
Where do I place the following code in my results.php if it needs to be before the “have_posts” loop?
global $searchandfilter; $sf_current_query = $searchandfilter->get(1726)->current_query(); echo $sf_current_query->is_filtered();
April 6, 2016 at 10:51 am #41768In reply to: Filter on EDD Search Results
RossKeymasterHi Adam
S&F doesn’t search tag names, nor does the default WP search – try your “Flowers” test with the old search and you will see (you can search tag names by combining S&F with Relevanssi).
RE the input box, thats the last step we missed!
So, each of the search input fields, that you have changed to be renamed to
_sf_s
, also has avalue
attribute.<input type="text" placeholder="<?php _e( 'Search', 'squarecode' ); ?>" value="<?php echo $searchresults; ?>" name="_sf_s" id="s" />
we need to get the S&F search term into this value attribute. I can see in both your header and search templates, that the query is populated with the value from this line:
<?php $searchresults = get_search_query(); ?>
So all we need to do is get S&F search query into that variable – from the docs you would replace the code above with –
<?php //Get the search term //replace <code>4243</code> with the ID of your search form global $searchandfilter; $sf_current_query = $searchandfilter->get(4243)->current_query(); $searchresults = $sf_current_query->get_search_term(); ?>
Thanks
March 17, 2016 at 5:54 pm #39703In reply to: Display search terms other than category do not work
AnonymousInactiveI finally found this solution:
$sarr = $sf_current_query->get_array();
$author = $sarr[authors][active_terms][0][name] ;
$fromDate = $sarr[_sf_post_date][active_terms][0][value] ;
$toDate = $sarr[_sf_post_date][active_terms][1][value];I hope it keeps on working always!
-
AuthorSearch Results