-
AuthorSearch Results
-
June 2, 2020 at 2:56 pm #246960
In reply to: Echo custom field name on results page
TrevorParticipantI have edited and tested it for you. This is the code I used in the end:
global $searchandfilter; $sf_current_query = $searchandfilter->get(1949)->current_query()->get_array(); $category = $sf_current_query['_sft_category']['active_terms'][0]["name"]; $county = $sf_current_query["_sfm_county"]["active_terms"][0]["name"]; if ($category) { echo $category . ", "; } else { echo "All Categories, "; } if ($county) { echo $county; } else { echo "All Counties"; }
You may edit that to make it look better though.
May 29, 2020 at 6:03 pm #246641In reply to: Echo custom field name on results page
AnonymousInactiveI do, thanks. However, it’s now outputting the text ‘ArrayAntigonish’ (or ‘Array’ + whatever county is selected) and it’s not outputting category name. I have tried to puzzle through this to see if I can work out how to fix it myself but my PHP just isn’t good enough.
Here’s a link to a sample results page.
What I’d like it to say is something like “You searched for Breweries, Distilleries, and Vineyards in Antigonish County” and then the results.
Below is the full code of results.php. If you can offer any more insight I’d be grateful.
<?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 this file is called directly, abort. if ( ! defined( 'ABSPATH' ) ) { exit; } if ( $query->have_posts() ) { ?> There are <?php echo $query->found_posts; ?> posts that match your search! <br /> <?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1949)->current_query()->get_array(); echo implode(", ",$sf_current_query['_sft_category']['active_terms']); $county = $sf_current_query["_sfm_county"]["active_terms"][0]["value"]; if ($county) { echo $county; } else { echo "All Counties"; } while ($query->have_posts()) { $query->the_post(); ?> <div> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p><?php the_excerpt(); ?></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( 'Next page', $query->max_num_pages ); ?></div> <div class="nav-next"><?php previous_posts_link( 'Previous page' ); ?></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"; } ?>
May 29, 2020 at 5:33 pm #246628In reply to: Echo custom field name on results page
TrevorParticipantAh. Try this then:
global $searchandfilter; $sf_current_query = $searchandfilter->get(1949)->current_query()->get_array(); echo implode(", ",$sf_current_query['_sft_category']['active_terms']); $county = $sf_current_query["_sfm_county"]["active_terms"][0]["value"]; if ($county) { echo $county; } else { echo "All Counties"; }
I am coding a bit blind here though. Notice how the second line changed, and the way the category output is changed?
March 31, 2020 at 2:21 pm #238475In reply to: Page Title For Search Results
TrevorParticipantSo, here is a search:
_sft_location=cotswolds
_sft_partysize=ten-guests
_sft_features=garden-patio,internetThe code I added was this (replace the 12345 with your form ID):
<div> <?php global $searchandfilter; $sf_current_query = $searchandfilter->get(12345)->current_query()->get_array(); $locations_filter = $sf_current_query["_sft_location"]["active_terms"][0]["name"]; if ( $locations_filter <> "") { echo '<div>Location: ' . $locations_filter . '</div>'; } $party_size_filter = $sf_current_query["_sft_partysize"]["active_terms"][0]["name"]; if ( $party_size_filter <> "") { echo '<div>Guests: ' . $party_size_filter . '</div>'; } $features_filter_array = $sf_current_query["_sft_features"]["active_terms"]; if ( $features_filter_array ) { echo '<div>Features: '; foreach($features_filter_array as $value) { $features_list .= $value["name"] . ", "; } echo rtrim($features_list, ", ") . '</div>'; } ?> </div>
March 19, 2020 at 4:26 pm #237221
TrevorParticipantYou seem to have customised the results.php file, but it must have errors as it also shows ‘no results found’?
This post might help you with code for what you want:
That code is for _sft_category and the id number is wrong, so maybe this?
global $searchandfilter; $sf_current_query = $searchandfilter->get(3637)->current_query(); $sf_current_query_array = $searchandfilter->get(3637)->current_query()->get_array(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo '<div>No category selected.</div>'; } else { echo '<div>' . $sf_current_query_array["_sft_menucats"]["active_terms"][0]["value"] . '</div>'; echo '<div>' . $sf_current_query_array["_sft_menucats"]["active_terms"][0]["id"]. '</div>'; echo '<div>' . category_description($sf_current_query_array["_sft_menucats"]["active_terms"][0]["id"]). '</div>'; }
Otherwise, are you able to send me temporary WordPress admin logins (ones you should later delete or disable) for the site so that I can look at the setup? Please use a Private Reply.
March 11, 2020 at 11:35 am #236248In reply to: Category description in search results
TrevorParticipantI added this code:
https://www.screencast.com/t/WYIjHhwBYb
This:
global $searchandfilter; $sf_current_query = $searchandfilter->get(332)->current_query(); $sf_current_query_array = $searchandfilter->get(332)->current_query()->get_array(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo '<div>No category selected.</div>'; } else { echo '<div>' . $sf_current_query_array["_sft_category"]["active_terms"][0]["value"] . '</div>'; echo '<div>' . $sf_current_query_array["_sft_category"]["active_terms"][0]["id"]. '</div>'; echo '<div>' . category_description($sf_current_query_array["_sft_category"]["active_terms"][0]["id"]). '</div>'; }
February 17, 2020 at 4:45 pm #234116In reply to: Search Term not showing on Custom Archive Page
TrevorParticipantIf you use this code you would get the whole array:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1902)->current_query()->get_array(); echo '<pre>',print_r($sf_current_query,true),'</pre>'; ?>
Then you can see what each is called and contains.
February 17, 2020 at 11:06 am #234049In reply to: Search Term not showing on Custom Archive Page
TrevorParticipantThe page title and that searched for part are both from the theme template, and not from our plugin. The template looks like it is a modified search.php or archive.php template that are only ever designed to display the search string, whereas you filter is far more complex.
You may need to refer to the theme authors as to how to alter/set the page title. WordPress does have some functions also to do this, but whether they would work would depend on the theme in use.
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
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 also look like you need some custom CSS:
.searchandfilter > ul { margin-left: 0; }
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.
-
AuthorSearch Results