Do you mean echo $sf_current_query->get_field_string("_sft_category"); with a t and not an m?
Does the guidance and examples in the documentation help?
AnonymousInactive
Hello,
when I try to output currently selected filter values, this is working:
echo $sf_current_query->get_field_string(“_sfm_category”);
But this is not working, as well as any filter that start with _sfm:
echo $sf_current_query->get_field_string(“_sfm_character”);
What can be reason?
Whilst it will give you a LOT of data, this php will print out the array contents (put it in that code):
echo '<pre>';
print_r($sf_current_query);
echo '</pre>';
MMM. If you DO select an author, and examine the $sf_current_query array, is the author data in there as a variable? Because you are not fetching from that array.
AnonymousInactive
Hi Trevor,
In fact, i’ve a search.php file for my results. I wrote this code which appears on the top of the results :
global $searchandfilter;
global $post;
$author_id = $post->post_author;
$author = get_the_author_meta('display_name', $author_id);
$sf_current_query = $searchandfilter->get(802)->current_query();
$num_res = $wp_query->post_count;
echo $sf_current_query->get_field_string("_sft_category").'<br />';
echo $sf_current_query->get_field_string("_sft_thematique").'<br />';
if($num_res == 0) {
echo 'Terme(s): '.$sf_current_query->get_search_term().'<br />';
}
echo 'Elément(s) trouvés(s): ' .$wp_query->found_posts;
I can display the author which is selected from the author select list but i don’t want to display anything if no author selected.
I need a valid snippet which might be :
if ($author_id != '0') {
echo $author.'<br />';
}
Thank you for your help.
Best regards.
AnonymousInactive
OK thats I got it.
For anyone else who stumbles across this here’s the full code to output the Search Query
Firstly this gets the Query (change number to your search form ID) – place in the loop in your template:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(54)->current_query();
$searchTerm = $sf_current_query->get_search_term();
and then you can echo out the query in your anywhere in your template
<?php echo $sf_current_query; ?>
You need instead to use code like this to get the query:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(339)->current_query();
Where 339 is the form ID.
You might need to dump the array to get an idea what is in it, but a search of the forum reveals some code snippets:
https://support.searchandfilter.com/forums/search/sf_current_query+searchandfilter+current_query/
I think it is possible that the next major release (V3, which we are working on right now) will have a much better way of doing this).
AnonymousInactive
Hello Trevor,
What i meant : You give some snippets to display some informations like thais :
global $searchandfilter;
$sf_current_query = $searchandfilter->get(802)->current_query();
echo $sf_current_query->get_field_string("_sft_category").'<br />';
echo $sf_current_query->get_field_string("_sft_thematique").'<br />';
echo 'Terme(s): '.$sf_current_query->get_search_term().'<br />';
echo 'Elément(s) trouvés(s): ' .$wp_query->found_posts;
I’d like to have a snippet to display the author chosen in my select list. If i try that code, it doesn’t work :
echo $sf_current_query->get_field_string("authors");
Is it possible to realize this ? It’s not in your documentation.
Thank you for your help.
Best regards.
AnonymousInactive
Ooops. I tried to create a code box with bbcode but it seems it doesn’t work here. Sorry for that! Here you have it again.
<?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(21899)->current_query();
if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
echo '<div> </div>';
} else {
if ( $query->have_posts() )
{
?>
Se han encontrado <strong><?php echo $query->found_posts; ?> resultados</strong><br />
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<div class='search-filter-results-list'>
<a href="<?php the_permalink(); ?>"><h2 class='search-filter-title'><?php the_title(); ?></h2>
<?php
if ( has_post_thumbnail() ) {
echo '<div class="menu-img">';
the_post_thumbnail("full");
echo '</div>';
}
?>
</a></div>
<?php
}
?>
<?php
}
else
{
echo "No se han encontrado resultados";
}
}
?>
AnonymousInactive
Thank you very much for such a nice plugin. It works like charm and we are very happy with it! Up until now we have managed to sort out all the little problems we’ve had by reading the forum, but I can’t find a solution to this one.
I have added a “Search field” to my form and, whenever I deliberately look for a term that doesn’t exist, instead of displaying the “No results found” message, it returns all the items unfiltered. Is there a way to solve this?
It may have something to do with my results .php, which I have edited quite a bit, but I’m not sure. This is the code I’m using for it:
[code]
<?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(21899)->current_query();
if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==””)) {
echo ‘<div> </div>’;
} else {
if ( $query->have_posts() )
{
?>
Se han encontrado <?php echo $query->found_posts; ?> resultados<br />
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<div class=’search-filter-results-list’>
“><h2 class=’search-filter-title’><?php the_title(); ?></h2>
<?php
if ( has_post_thumbnail() ) {
echo ‘<div class=”menu-img”>’;
the_post_thumbnail(“full”);
echo ‘</div>’;
}
?>
</div>
<?php
}
?>
<?php
}
else
{
echo “No se han encontrado resultados”;
}
}
?>
[/code]