-
AuthorSearch Results
-
March 10, 2017 at 2:10 pm #95973
In reply to: Accessing the Search Data
AnonymousInactiveSorry for the mistake, I mean
echo $sf_current_query->get_field_string("_sft_category");
witht
I did things as in the documentation, but cant output any _sfm filters
March 10, 2017 at 2:07 pm #95968In reply to: Accessing the Search Data
TrevorParticipantDo you mean
echo $sf_current_query->get_field_string("_sft_category");
with at
and not anm
?Does the guidance and examples in the documentation help?
February 23, 2017 at 7:05 pm #92526In reply to: Check if a select list data is selected
TrevorParticipantWhilst 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>';
February 23, 2017 at 5:25 pm #92504In reply to: Check if a select list data is selected
TrevorParticipantMMM. 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.February 23, 2017 at 9:04 am #92230In reply to: Check if a select list data is selected
AnonymousInactiveHi 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.
February 22, 2017 at 11:08 pm #92142In reply to: Showing the search query
AnonymousInactiveOK 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; ?>
February 22, 2017 at 9:17 pm #92106In reply to: Showing the search query
TrevorParticipantYou 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).
February 21, 2017 at 8:29 am #91601In reply to: Display author name in template
AnonymousInactiveHello 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.
February 20, 2017 at 4:51 pm #91473
AnonymousInactiveOoops. 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"; } } ?>
February 16, 2017 at 4:09 am #90518In reply to: Post Meta Date Range
RossKeymasterHi Max
I had a look, it seems to me there is something wrong with your code sample.
The filter receives a
$query_args
object, which contains the wp_query args that S&F defines, and at the end of the function it needs to return this$query_args
object.Inside the function you are free to modify this as you want, which it looks like you got close to do doing but not quite there..
You add your meta query to a new variable called
$args
, which never gets used.I would do it like the following (untested – please also copy & paste into editor to see my comments, this is a bit clunky):
<?php function filter_function_name( $query_args, $sfid ) { if( $sfid == 940 ) { // I would use some known values for testing (I just made some dates up here) $tender_start = "20170101"; $tender_end = "20170101"; /*global $searchandfilter; $sf_current_query = $searchandfilter->get(940)->current_query(); $array_data = $sf_current_query->get_array(); $tender_start = $array_data['_sfm_tender_start']['active_terms'][0]['value']; $tender_end = $array_data['_sfm_tender_end']['active_terms'][0]['value'];*/ //if we want to play nice and not completely replace the existing meta query args //there might be, then we need to check if some meta queries already exist and treat it differently $meta_query = array( 'relation' => 'AND', array( 'key' => 'tender_start', 'compare' => '>=', 'value' => $tender_start ), array( 'key' => 'tender_end', 'compare' => '<=', 'value' => $tender_end ) ); if((isset($query_args['meta_query']))&&(is_array($query_args['meta_query']))) {//this means there are some meta queries already here, so push this one onto the end array_push($query_args['meta_query'], $meta_query); } else {//else there aren't any meta queries //$query_args['meta_query'] should always be an array of meta queries according to wp docs $query_args['meta_query'] = array($meta_query); } // not sure if you need these, you should set the order via the S&F admin (in the <code>posts</code> tab) $query_args['meta_key'] = 'tender_start'; $query_args['orderby'] = 'meta_value_num'; $query_args['order'] = 'ASC'; } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
I’ve written that in my editor so it should be correct syntax, but I haven’t actually tested it, its just showing you how to properly use the $query_args to make the changes you want.
Hope that helps
-
AuthorSearch Results