-
AuthorSearch Results
-
May 12, 2017 at 2:44 pm #108481
In reply to: How to show the currently selected title only
TrevorParticipantAh, I see the erro. Not sure how many steps back you will need to take though.
$sf_current_query = $searchandfilter->get(504)->current_query()->get_array();
And look at what is in THAT array using print_r.
March 22, 2017 at 5:44 pm #98807In reply to: Null Fields Not Returning Results
AnonymousInactiveWooo, that got it. Thank you for your patience.
For anyone else with this issue please see my code below. Probably not perfect but it works. 🙂
// Exclude the default range values from the search as they are meaning the search returns no results function remove_default_range( $query_args, $sfid ) { //if search form ID = 225, the do something with this query if($sfid==25 && $query_args) { if((isset($query_args['meta_query']))&&(is_array($query_args['meta_query']))) { global $searchandfilter; $sf_current_query = $searchandfilter->get(25)->current_query()->get_array(); /* echo "<pre>"; print_r($sf_current_query); echo "</pre>";*/ echo $sf_current_query['_sfm_minimum_per_round'][0]['value']; if($sf_current_query['_sfm_minimum_per_round'][0]['value'] == '0' && $sf_current_query['_sfm_minimum_per_round'][0]['value'] == '50000') { unset($sf_current_query['_sfm_minimum_per_round']); } if($sf_current_query['_sfm_minimum_per_season'][0]['value'] == '0' && $sf_current_query['_sfm_minimum_per_season'][0]['value'] == '1000000') { unset($sf_current_query['_sfm_minimum_per_season']); } } } return $query_args; } add_filter( 'sf_edit_query_args', 'remove_default_range', 20, 2 );
March 22, 2017 at 4:54 pm #98769In reply to: Null Fields Not Returning Results
TrevorParticipantIt is a while since I looked at the array, but I think I did something like this:
global $searchandfilter; $sf_current_query = $searchandfilter->get(25)->current_query()->get_array(); echo "<pre>"; print_r($sf_current_query); echo "</pre>";
March 10, 2017 at 2:36 pm #95975In reply to: Accessing the Search Data
AnonymousInactiveI found some workaround, to display currently selected value:
$tmp = $sf_current_query->get_array(); echo $tmp["_sfm_character"]["active_terms"][0]["name"];
But it may be a bug in
get_field_string
method from documentation, which is not working in my case:echo $sf_current_query->get_field_string("_sfm_character");
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
February 11, 2017 at 11:45 pm #89576In reply to: Post Meta Date Range
AnonymousInactiveThank for your answer. Do you have a code sample? I tried some but no result.
function filter_function_name( $query_args, $sfid ) { if( $sfid == 940 ) { 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']; $args = array( 'meta_key' => 'tender_start', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'tender_start', 'compare' => '>=', 'value' => $tender_start ), array( 'key' => 'tender_end', 'compare' => '<=', 'value' => $tender_end ) ) ); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
December 30, 2016 at 4:43 pm #79288
TrevorParticipantMarjan, we seem to have successfully coded up the solution for this, using a PHP snippet:
<?php global $searchandfilter; $sf_query = $searchandfilter->get(3217)->current_query(); if ($sf_query->is_filtered()) { $sf_current_query = $searchandfilter->get(3217)->current_query()->get_array(); echo "<b>Prikaz rezultatov za...</b>"; $cat_string = ""; foreach($sf_current_query['_sft_category']['active_terms'] as $item) { $cat_string .= $item['name'] . ", "; } $starost_string = ""; foreach($sf_current_query['_sfm_starost']['active_terms'] as $item) { $starost_string .= $item['name'] . ", "; } if (($sf_current_query['_sft_category']['active_terms'][0]['name'])<>"") echo "<div>PRODUKTI: " . substr($cat_string, 0, -2) . "</div>"; if (($sf_current_query['_sft_post_tag']['active_terms'][0]['name'])<>"") echo "<div>STANJA: " . ($sf_current_query['_sft_post_tag']['active_terms'][0]['name']) . "</div>"; if (($sf_current_query['_sfm_kakovost_spremembe']['active_terms'][0]['name'])<>"") echo "<div>KAKOVOST SPREMEMBE: " . ($sf_current_query['_sfm_kakovost_spremembe']['active_terms'][0]['name']) . "</div>"; if (($sf_current_query['_sfm_starost']['active_terms'][0]['name'])<>"") echo "<div>STAROST: " . substr($starost_string, 0, -2) . "</div>"; if (($sf_current_query['_sfm_vrsta_primera']['active_terms'][0]['name'])<>"") echo "<div>VRSTA PRIMERA: " . ($sf_current_query['_sfm_vrsta_primera']['active_terms'][0]['name']) . "</div>"; } ?>
So I will close this now. Great to speak with you on Skype.
December 17, 2016 at 9:13 am #77226
TrevorParticipantOK, nearly there. This is the code we have so far:
<?php global $searchandfilter; $sf_query = $searchandfilter->get(3217)->current_query(); if ($sf_query->is_filtered()) { ?> <div>Found <?php echo $sf_query->found_posts; ?> Results</div> <?php $sf_current_query = $searchandfilter->get(3217)->current_query()->get_array(); if (($sf_current_query['_sft_category']['active_terms'][0]['name'])<>"") echo "<div>KATEGORIJE: " . ($sf_current_query['_sft_category']['active_terms'][0]['name']) . "</div>"; if (($sf_current_query['_sft_post_tag']['active_terms'][0]['name'])<>"") echo "<div>OZNAKE: " . ($sf_current_query['_sft_post_tag']['active_terms'][0]['name']) . "</div>"; if (($sf_current_query['_sfm_kakovost_spremembe']['active_terms'][0]['name'])<>"") echo "<div>KAKOVOST SPREMEMBE: " . ($sf_current_query['_sfm_kakovost_spremembe']['active_terms'][0]['name']) . "</div>"; if (($sf_current_query['_sfm_starost']['active_terms'][0]['name'])<>"") echo "<div>STAROST: " . ($sf_current_query['_sfm_starost']['active_terms'][0]['name']) . "</div>"; if (($sf_current_query['_sfm_vrsta_primera']['active_terms'][0]['name'])<>"") echo "<div>VRSTA PRIMERA: " . ($sf_current_query['_sfm_vrsta_primera']['active_terms'][0]['name']) . "</div>"; } ?>
And we know that the only part NOT working is:
<div>Found <?php echo $sf_query->found_posts; ?> Results</div>
December 4, 2016 at 6:26 pm #73970In reply to: How to output the type of search done
AnonymousInactiveHey Trevor,
Managed to figure it out.
For the record here’s what I used (replacing 725 with whatever your specific search ID is..)
<?php
global $searchandfilter;
$sf_current_query = $searchandfilter->get(725)->current_query();$array_data = $sf_current_query->get_array();
$typeOfSearch = $array_data[“_sf_sort_order”][“active_terms”][0][“value”];echo $typeOfSearch ;
?>
Keith
November 30, 2016 at 5:43 pm #73321In reply to: How to get Post Meta values?
AnonymousInactiveHi, we were able to get the meta values we needed with get_array();
And for those curious the code we used was (square-feet is our custom field):
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(315)->current_query(); $array_data = $sf_current_query->get_array(); $squarefeet_min = $array_data["_sfm_square-feet"]["active_terms"][0]["value"]; $squarefeet_max = $array_data["_sfm_square-feet"]["active_terms"][1]["value"]; ?>
Thanks again for the help.
-
AuthorSearch Results