Forums Forums Search Search Results for 'active_terms 0 name'

Viewing 10 results - 31 through 40 (of 45 total)
  • Author
    Search Results
  • #90518

    In reply to: Post Meta Date Range


    Ross
    Keymaster

    Hi 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

    #89576

    In reply to: Post Meta Date Range


    Anonymous
    Inactive

    Thank 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 );

    Trevor
    Participant

    Marjan, 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.


    Trevor
    Participant

    OK, 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>
    
    #52218

    In reply to: Getting value from url


    Anonymous
    Inactive

    Well, that breaks the code, the part where the echo should be doens’t show anymore. The rest doesn’t show neither.

    <?php global $searchandfilter;
    $sf_current_query = $searchandfilter->get(15)->current_query()->get_array();
    foreach($sf_current_query as $key) {
      echo '<div>' . $key['name'] . '</div>';
      echo '<div>' . $key['active_terms'][0]['name'] . '</div>';
    } ?>
    #52114

    In reply to: Getting value from url


    Trevor
    Participant

    What does this give?

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query()->get_array();
    foreach($sf_current_query as $key) {
      echo '<div>' . $key['name'] . '</div>';
      echo '<div>' . $key['active_terms'][0]['name'] . '</div>';
    }
    #52109

    In reply to: Getting value from url


    Anonymous
    Inactive

    Search_Filter_Active_Query Object ( [sfid] => 15 [is_set:Search_Filter_Active_Query:private] => 1 [query_array:Search_Filter_Active_Query:private] => Array ( [_sft_aantal_personen] => Array ( [name] => Aantal personen [singular_name] => Aantal personen [all_items_label] => Alle Aantal personen [type] => taxonomy [active_terms] => Array ( [0] => Array ( [id] => 3 [name] => 15 of meer personen [value] => 15-of-meer-personen [count] => 1 ) ) ) [_sft_arrangementstype] => Array ( [name] => Arrangementstype [singular_name] => Arrangementstype [all_items_label] => Alle Arrangementstype [type] => taxonomy [active_terms] => Array ( [0] => Array ( [id] => 5 [name] => Borrelen [value] => borrelen [count] => 1 ) [1] => Array ( [id] => 31 [name] => Italiaans menu [value] => italiaans-menu [count] => 1 ) [2] => Array ( [id] => 33 [name] => Sushi menu [value] => sushi-menu [count] => 1 ) ) ) [_sft_type_boot] => Array ( [name] => Type boten [singular_name] => Type boot [all_items_label] => Alle Type boten [type] => taxonomy [active_terms] => Array ( [0] => Array ( [id] => 19 [name] => Salonboot [value] => salonboot [count] => 1 ) ) ) ) [form_fields:Search_Filter_Active_Query:private] => Array ( [_sft_aantal_personen] => Array ( [type] => taxonomy [input_type] => checkbox [heading] => 1. Met hoeveel personen bent u? [accessibility_label] => [all_items_label] => [show_count] => 1 [hide_empty] => 1 [hierarchical] => 0 [include_children] => 0 [drill_down] => 0 [sync_include_exclude] => 1 [combo_box] => 0 [operator] => and [order_by] => default [order_dir] => asc [exclude_ids] => [taxonomy_name] => aantal_personen ) [_sft_arrangementstype] => Array ( [type] => taxonomy [input_type] => checkbox [heading] => 2. Wat wilt u doen? [accessibility_label] => [all_items_label] => [show_count] => 1 [hide_empty] => 1 [hierarchical] => 1 [include_children] => 1 [drill_down] => 0 [sync_include_exclude] => 1 [combo_box] => 0 [operator] => and [order_by] => default [order_dir] => asc [exclude_ids] => [taxonomy_name] => arrangementstype ) [_sft_type_boot] => Array ( [type] => taxonomy [input_type] => checkbox [heading] => 3. Wat voor boot type wilt u? [accessibility_label] => [all_items_label] => [show_count] => 1 [hide_empty] => 1 [hierarchical] => 0 [include_children] => 0 [drill_down] => 0 [sync_include_exclude] => 1 [combo_box] => 0 [operator] => and [order_by] => default [order_dir] => asc [exclude_ids] => [taxonomy_name] => type_boot ) [_sft_type_boot_2] => Array ( [type] => taxonomy [input_type] => checkbox [heading] => [accessibility_label] => [all_items_label] => [show_count] => 1 [hide_empty] => 1 [hierarchical] => 0 [include_children] => 0 [drill_down] => 0 [sync_include_exclude] => 1 [combo_box] => 0 [operator] => and [order_by] => id [order_dir] => asc [exclude_ids] => [taxonomy_name] => type_boot_2 ) [_sft_boot_opties] => Array ( [type] => taxonomy [input_type] => checkbox [heading] => 4. Wat wilt u aan boord hebben? [accessibility_label] => [all_items_label] => [show_count] => 1 [hide_empty] => 1 [hierarchical] => 0 [include_children] => 0 [drill_down] => 0 [sync_include_exclude] => 1 [combo_box] => 0 [operator] => and [order_by] => default [order_dir] => asc [exclude_ids] => [taxonomy_name] => boot_opties ) [reset] => Array ( [type] => reset [heading] => [input_type] => button [label] => Reset ) [submit] => Array ( [type] => submit [heading] => [label] => Submit ) ) [plugin_slug] => search-filter [form_settings] => Array ( [use_template_manual_toggle] => 1 [enable_auto_count] => 1 [auto_count_refresh_mode] => 1 [auto_count_deselect_emtpy] => 0 [template_name_manual] => search.php [page_slug] => vaararrangementen [post_types] => Array ( [post] => 1 ) [post_status] => Array ( [publish] => 1 ) [use_ajax_toggle] => 1 [scroll_to_pos] => 0 [custom_scroll_to] => [treat_child_posts_as_parent] => 0 [auto_submit] => 1 [display_results_as] => shortcode [update_ajax_url] => 1 [only_results_ajax] => 1 [ajax_target] => #main-filter [results_url] => http://ontwikkeling.puur.nl/boottochtamsterdam/vaararrangementen/ [ajax_links_selector] => .pagination a [results_per_page] => 10 [exclude_post_ids] => [field_relation] => and [default_sort_by] => 0 [sticky_posts] => [default_sort_dir] => desc [default_meta_key] => _edit_last [default_sort_type] => numeric [secondary_sort_by] => 0 [secondary_sort_dir] => desc [secondary_meta_key] => _edit_last [secondary_sort_type] => numeric [taxonomies_settings] => Array ( [category] => Array ( [include_exclude] => include [ids] => ) [post_tag] => Array ( [include_exclude] => include [ids] => ) [post_format] => Array ( [include_exclude] => include [ids] => ) [aantal_personen] => Array ( [include_exclude] => include [ids] => ) [arrangementstype] => Array ( [include_exclude] => include [ids] => ) [boot_opties] => Array ( [include_exclude] => include [ids] => ) [type_boot] => Array ( [include_exclude] => include [ids] => ) [type_boot_2] => Array ( [include_exclude] => include [ids] => ) ) ) [cache_table_name] => wp_search_filter_cache [term_results_table_name] => wp_search_filter_term_results [field_values] => Array ( [_sft_aantal_personen] => Array ( [0] => 15-of-meer-personen ) [_sft_arrangementstype] => Array ( [0] => borrelen [1] => italiaans-menu [2] => sushi-menu ) [_sft_type_boot] => Array ( [0] => salonboot ) ) )

    #52108

    In reply to: Getting value from url


    Anonymous
    Inactive

    Sorry for the late reply. This is what I get using above code:
    Search_Filter_Active_Query Object ( [sfid] => 15 [is_set:Search_Filter_Active_Query:private] => 1 [query_array:Search_Filter_Active_Query:private] => Array ( [_sft_aantal_personen] => Array ( [name] => Aantal personen [singular_name] => Aantal personen [all_items_label] => Alle Aantal personen [type] => taxonomy [active_terms] => Array ( [0] => Array ( [id] => 3 [name] => 15 of meer personen [value] => 15-of-meer-personen [count] => 1 ) ) ) [_sft_arrangementstype] => Array ( [name] => Arrangementstype [singular_name] => Arrangementstype [all_items_label] => Alle Arrangementstype [type] => taxonomy [active_terms] => Array ( [0] => Array ( [id] => 5 [name] => Borrelen [value] => borrelen [count] => 1 ) [1] => Array ( [id] => 31 [name] => Italiaans menu [value] => italiaans-menu [count] => 1 ) [2] => Array ( [id] => 33 [name] => Sushi menu [value] => sushi-menu [count] => 1 ) ) ) [_sft_type_boot] => Array ( [name] => Type boten [singular_name] => Type boot [all_items_label] => Alle Type boten [type] => taxonomy [active_terms] => Array ( [0] => Array ( [id] => 19 [name] => Salonboot [value] => salonboot [count] => 1 ) ) ) ) [form_fields:Search_Filter_Active_Query:private] => Array ( [_sft_aantal_personen] => Array ( [type] => taxonomy [input_type] => checkbox [heading] => 1. Met hoeveel personen bent u? [accessibility_label] => [all_items_label] => [show_count] => 1 [hide_empty] => 1 [hierarchical] => 0 [include_children] => 0 [drill_down] => 0 [sync_include_exclude] => 1 [combo_box] => 0 [operator] => and [order_by] => default [order_dir] => asc [exclude_ids] => [taxonomy_name] => aantal_personen ) [_sft_arrangementstype] => Array ( [type] => taxonomy [input_type] => checkbox [heading] => 2. Wat wilt u doen? [accessibility_label] => [all_items_label] => [show_count] => 1 [hide_empty] => 1 [hierarchical] => 1 [include_children] => 1 [drill_down] => 0 [sync_include_exclude] => 1 [combo_box] => 0 [operator] => and [order_by] => default [order_dir] => asc [exclude_ids] => [taxonomy_name] => arrangementstype ) [_sft_type_boot] => Array ( [type] => taxonomy [input_type] => checkbox [heading] => 3. Wat voor boot type wilt u? [accessibility_label] => [all_items_label] => [show_count] => 1 [hide_empty] => 1 [hierarchical] => 0 [include_children] => 0 [drill_down] => 0 [sync_include_exclude] => 1 [combo_box] => 0 [operator] => and [order_by] => default [order_dir] => asc [exclude_ids] => [taxonomy_name] => type_boot ) [_sft_type_boot_2] => Array ( [type] => taxonomy [input_type] => checkbox [heading] => [accessibility_label] => [all_items_label] => [show_count] => 1 [hide_empty] => 1 [hierarchical] => 0 [include_children] => 0 [drill_down] => 0 [sync_include_exclude] => 1 [combo_box] => 0 [operator] => and [order_by] => id [order_dir] => asc [exclude_ids] => [taxonomy_name] => type_boot_2 ) [_sft_boot_opties] => Array ( [type] => taxonomy [input_type] => checkbox [heading] => 4. Wat wilt u aan boord hebben? [accessibility_label] => [all_items_label] => [show_count] => 1 [hide_empty] => 1 [hierarchical] => 0 [include_children] => 0 [drill_down] => 0 [sync_include_exclude] => 1 [combo_box] => 0 [operator] => and [order_by] => default [order_dir] => asc [exclude_ids] => [taxonomy_name] => boot_opties ) [reset] => Array ( [type] => reset [heading] => [input_type] => button [label] => Reset ) [submit] => Array ( [type] => submit [heading] => [label] => Submit ) ) [plugin_slug] => search-filter [form_settings] => Array ( [use_template_manual_toggle] => 1 [enable_auto_count] => 1 [auto_count_refresh_mode] => 1 [auto_count_deselect_emtpy] => 0 [template_name_manual] => search.php [page_slug] => vaararrangementen [post_types] => Array ( [post] => 1 ) [post_status] => Array ( [publish] => 1 ) [use_ajax_toggle] => 1 [scroll_to_pos] => 0 [custom_scroll_to] => [treat_child_posts_as_parent] => 0 [auto_submit] => 1 [display_results_as] => shortcode [update_ajax_url] => 1 [only_results_ajax] => 1 [ajax_target] => #main-filter [results_url] => http://ontwikkeling.puur.nl/boottochtamsterdam/vaararrangementen/ [ajax_links_selector] => .pagination a [results_per_page] => 10 [exclude_post_ids] => [field_relation] => and [default_sort_by] => 0 [sticky_posts] => [default_sort_dir] => desc [default_meta_key] => _edit_last [default_sort_type] => numeric [secondary_sort_by] => 0 [secondary_sort_dir] => desc [secondary_meta_key] => _edit_last [secondary_sort_type] => numeric [taxonomies_settings] => Array ( [category] => Array ( [include_exclude] => include [ids] => ) [post_tag] => Array ( [include_exclude] => include [ids] => ) [post_format] => Array ( [include_exclude] => include [ids] => ) [aantal_personen] => Array ( [include_exclude] => include [ids] => ) [arrangementstype] => Array ( [include_exclude] => include [ids] => ) [boot_opties] => Array ( [include_exclude] => include [ids] => ) [type_boot] => Array ( [include_exclude] => include [ids] => ) [type_boot_2] => Array ( [include_exclude] => include [ids] => ) ) ) [cache_table_name] => wp_search_filter_cache [term_results_table_name] => wp_search_filter_term_results [field_values] => Array ( [_sft_aantal_personen] => Array ( [0] => 15-of-meer-personen ) [_sft_arrangementstype] => Array ( [0] => borrelen [1] => italiaans-menu [2] => sushi-menu ) [_sft_type_boot] => Array ( [0] => salonboot ) ) )

    #51898

    In reply to: Getting value from url


    Anonymous
    Inactive

    Hi Trevor, I got it to work.
    Using this code:

    function refresh() {
    		$('.things').load(document.URL +  ' .things');
    	}
    	//detects the start of an ajax request being made
    		$(document).on("sf:ajaxstart", ".searchandfilter", function(){
    		  console.log("ajax start");
    
    		});
    
    		//detects when the ajax request has finished and the content has been updated
    		// - add scripts that apply to your results here
    
    		$(document).on("sf:ajaxfinish", ".searchandfilter", function(){
    			console.log("ajax complete");
    			//so load your lightbox or JS scripts here again
    			refresh();
    		});
    
    		//an event fired when S&F is initialised and S&F scripts have been loaded
    		$(document).on("sf:init", ".searchandfilter", function(){
    			console.log("S&F JS initialised");
    		});

    The only thing is, it posts the whole category and name: Aantal personen: 20 of meer personen. You’ve already tackelled this problem here: https://support.searchandfilter.com/forums/topic/how-to-style-the-search-data/

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query()->get_array();
    foreach($sf_current_query as $key) {
      echo '<div>' . $key['active_terms'][0]['name'] . '</div>';
    }

    Which would display “20 of meer personen” but What I would like is to have it show “Aantal personen:<br />20 of meer personen.

    What to do?

    #46959

    Trevor
    Participant

    OK

    I have re-written that a bit and added a new line after each line output. It may not work, but it is better code:

    <?php
      global $searchandfilter;
      $sf_current_query = $searchandfilter->get(2327)->current_query()->get_array();
      if (isset ($sf_current_query)) {
        foreach($sf_current_query as $key) {
          echo '<span class="results-term">' . $key['active_terms'][0]['name'] . '</span><br />';
        }
      }
    ?>
Viewing 10 results - 31 through 40 (of 45 total)