-
AuthorSearch Results
-
March 22, 2017 at 5:44 pm #98807
In 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>";
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.
November 17, 2016 at 4:38 pm #70909In reply to: Settings & Default / Post (wrong default order)
AnonymousInactivefunction sf_filter_query_args( $query_args, $sfid ) {
if($sfid==1225){
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1225)->current_query();$sf_current_query->get_field_string(“_sfm_event_archives”);
$_sfm_event_archives_array = $sf_current_query->get_array();
$archive_is_check = $_sfm_event_archives_array[_sfm_event_archives][active_terms][0][value];//print_r($archive_is_check);
if($archive_is_check != ‘1’){
$args_custom = array(
“meta_key” => “imic_event_start_dt”,
“orderby” => “meta_value_num”,
“order” => “ASC”,
“meta_query” => Array (
“event_archives” => Array (
“key” => “event_archives”,
“value” => “0”
)
)
);$query_args = array_merge($query_args, $args_custom);
}// si aucun filtre d’appliqué
//if($sf_current_query->is_filtered()!=1){}}
return $query_args;
}
add_filter( ‘sf_edit_query_args’, ‘sf_filter_query_args’, 100, 2 );November 17, 2016 at 4:37 pm #70903In reply to: Settings & Default / Post (wrong default order)
AnonymousInactiveHi,
thanks for your help!!!
It wasn’t the wpml plugin,
but the custom code (that I was sure it wasn’t in cause)
I had to add the bold section here to make it workfunction sf_filter_query_args( $query_args, $sfid ) { if($sfid==1225){ global $searchandfilter; $sf_current_query = $searchandfilter->get(1225)->current_query(); $sf_current_query->get_field_string("_sfm_event_archives"); $_sfm_event_archives_array = $sf_current_query->get_array(); $archive_is_check = $_sfm_event_archives_array[_sfm_event_archives][active_terms][0][value]; //print_r($archive_is_check); if($archive_is_check != '1'){ $args_custom = array( <strong>"meta_key" => "imic_event_start_dt", "orderby" => "meta_value_num", "order" => "ASC",</strong> "meta_query" => Array ( "event_archives" => Array ( "key" => "event_archives", "value" => "0" ) ) ); $query_args = array_merge($query_args, $args_custom); } // si aucun filtre d'appliqué //if($sf_current_query->is_filtered()!=1){} } return $query_args; } add_filter( 'sf_edit_query_args', 'sf_filter_query_args', 100, 2 );
Thanks again for your help guys!
Really nice plugin! -
AuthorSearch Results