-
AuthorSearch Results
-
July 22, 2016 at 9:41 am #51898
In reply to: Getting value from url
AnonymousInactiveHi Trevor, I got it to work.
Using this code:function refresh() { $('.things').load(document.URL + ' .things'); } //detects the start of an ajax request being made $(document).on("sf:ajaxstart", ".searchandfilter", function(){ console.log("ajax start"); }); //detects when the ajax request has finished and the content has been updated // - add scripts that apply to your results here $(document).on("sf:ajaxfinish", ".searchandfilter", function(){ console.log("ajax complete"); //so load your lightbox or JS scripts here again refresh(); }); //an event fired when S&F is initialised and S&F scripts have been loaded $(document).on("sf:init", ".searchandfilter", function(){ console.log("S&F JS initialised"); });
The only thing is, it posts the whole category and name: Aantal personen: 20 of meer personen. You’ve already tackelled this problem here: https://support.searchandfilter.com/forums/topic/how-to-style-the-search-data/
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>'; }
Which would display “20 of meer personen” but What I would like is to have it show “Aantal personen:<br />20 of meer personen.
What to do?
July 20, 2016 at 5:38 pm #51738In reply to: Shortcode results: don't display results until click
TrevorParticipantHi
I found two errors (one was ours, one yours), so here is the fixed code (I do not know if this will work):
<?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(44)->current_query(); if ($sf_current_query->is_filtered()) { ?> <?php echo $query->found_posts; ?> Firm(s) Meet All Selected Criteria<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> <h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6> <p><?php the_tags(); ?></p> </div> <hr/> <?php } ?> <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 firms meet all of your criteria. Try unchecking some boxes."; } } ?>
May 29, 2016 at 3:20 pm #46964In reply to: displaying search terms without labels
AnonymousInactivegot it! here is the solution.
<?php global $wp_query; $sf_current_query = $wp_query->query_vars['_sft_position']; ?> <?php if (isset ($sf_current_query)) : ?> <?php echo '<span class="results-term">' . $sf_current_query . '</span>'; ?> <?php endif; ?>
the vars can be changed to any search term you have.
May 29, 2016 at 10:20 am #46959In reply to: displaying search terms without labels
TrevorParticipantOK
I have re-written that a bit and added a new line after each line output. It may not work, but it is better code:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(2327)->current_query()->get_array(); if (isset ($sf_current_query)) { foreach($sf_current_query as $key) { echo '<span class="results-term">' . $key['active_terms'][0]['name'] . '</span><br />'; } } ?>
May 6, 2016 at 6:41 pm #44951In 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.
-
AuthorSearch Results