-
AuthorSearch Results
-
February 17, 2020 at 4:24 pm #234105
In reply to: Search Term not showing on Custom Archive Page
AnonymousInactiveSo i was able to use your documentation to grab the following query output: However, when i attempt to call the field _sfm_city it does not display anything. This is a Meta Key, does that matter? My attempt to display it is listed below
Array ( [_sft_specialties] => Array ( [name] => specialties [singular_name] => Specialty [all_items_label] => All Items [type] => taxonomy [active_terms] => Array ( [0] => Array ( [id] => 355 [name] => Test Matter Type [value] => test-matter-type [count] => 1 ) ) ) [_sft_providers-category] => Array ( [name] => Categories [singular_name] => Categories [all_items_label] => Categories [type] => taxonomy [active_terms] => Array ( [0] => Array ( [id] => 68 [name] => Patent Search [value] => patent-search [count] => 1 ) ) ) [_sft_operatingcountries] => Array ( [name] => Operation Countries [singular_name] => Operating Countries [all_items_label] => All Operating Countries [type] => taxonomy [active_terms] => Array ( [0] => Array ( [id] => 145 [name] => Denmark [value] => denmark [count] => 1 ) ) ) [_sfm_city] => Array ( [name] => [singular_name] => [all_items_label] => [type] => post_meta [active_terms] => Array ( [0] => Array ( [name] => HARARE [value] => HARARE ) ) ) )
`<?php
//Get a single fields values using labels
//replace1526
with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1902)->current_query();
echo $sf_current_query->get_field_string(“_sft_city”);?>
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; }
February 17, 2020 at 10:51 am #234043In 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>
-
AuthorSearch Results