Forums Forums Search Search Results for 'function sf_edit_query_args'

Viewing 10 results - 91 through 100 (of 123 total)
  • Author
    Search Results
  • #124848

    Anonymous
    Inactive

    Hi Trevor.

    I tryed using print_r and var_dump in functions.php but nothing is showing up on front-end. Like below:

    
    
    function filter_function_name( $args, $sfid ) {
    
    		//if search form ID = XX, the do something with this query
    		if ( $sfid == 2817 ) {
    
    			var_dump($args['post__in']);
                            print_r($args['post__in']);
    
    		}
    
    		return $args;
    	}
    	add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 200 );
    

    I tryed using var_dump($args['post__in']); in my custom page template and it returns NULL.

    #122190

    Anonymous
    Inactive

    Hi Trevor,

    We renewed our license. Thanks for the reminder!

    I’m trying to walk through the doc you shared and having a little trouble. Essentially, I just want to say that for Search Form 2051 the Category should always be All Items. Even when a user has selected a category that is being used with the other Search result filter on the page.

    Here’s the code from the doc with the appropriate Search Form ID:

    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 2051, the do something with this query
    	if($sfid==2051)
    	{
    		//modify $query_args here before returning it
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    I’ve tried to figure out the syntax for saying Category == All without luck.

    Would appreciate your help.

    Thanks!

    #99219

    Anonymous
    Inactive

    Hi Trevor,
    some of my WooCommerce products have a meta key “_tribe_event_starttime” and with your plugin I have setup an AJAX filter ordering these products by that meta key.
    Everything was fine for weeks but today I realized that the order has fallen back to the WC default (creation) “date”. You can see the result list by clicking on one of the big images on the top.

    https://obsthof-am-steinberg.de/produkt-kategorie/event-feste-kinder-musik/

    As you can see the AJAX requests has the GET parameter orderby=date and I tried to alter this order by hooking into your filter which I found here on your website:

    // alter query for search & filter results
    add_filter( ‘sf_edit_query_args’, ‘sf_orderby_eventdate’, 10, 2 );
    function sf_orderby_eventdate ($query_args, $sfid) {
    if ($sfid == 6047) {
    $query_args[“meta_key”] = ‘_tribe_event_starttime’;
    $query_args[“order_by”] = ‘meta_value’;
    $query_args[“order”] = ‘ASC’;
    }
    return $query_args;
    }

    Without success. I have installed WP Super Cache last week. Could this be the reason? Is there anything I missed or doing wrong?

    Thank you for your support!
    Oliver

    Now I am

    #98807

    Anonymous
    Inactive

    Wooo, 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 );
    #98705

    Anonymous
    Inactive

    Sorry to bother you, I’m trying to modify the query, however the $query_args[‘meta_query’] is returning a blank array whenever I print it out. This is even after I have altered a field and submitted the form.

    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']))) {
          print_r($query_args['meta_query']);
    		}			
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'remove_default_range', 20, 2 );
    #93355

    In reply to: Meta sort order


    Anonymous
    Inactive

    Might have made some progress. When I change the priority I now get no results instead of results in the wrong order. Here’s a code sample:

    function filter_sort_by_start_date( $query_args, $sfid ) {
    
    if( $sfid==2298 ) {
        $query_args = array(
          'meta_key' => 'class_date',
          'orderby' => 'meta_value_num',
          'order' => 'DESC'
        );
    }
    
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_sort_by_start_date', 2000, 2 );

    I’m getting the “no result” result even if I comment out the other ‘pre_get_posts’ calls.

    #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 );
    #87002

    Trevor
    Participant

    mmm. OK. are you creating wordpress pages and then using a shortcode or similar to place a given group on a given page? Do you have a custom field on the pages to hold the ID of the group?

    What I am thinking is that you could have a hidden field in the form which is the group (or group ID).

    Then, in the child theme functions.php you can have some custom PHP that checks if a page is being loaded, and if it is, to find the value held in the custom field that holds the group ID, and if it does have a group ID, to then use our sf_edit_query_args filter to modify the group ID field in the form to be that of the custom field on that page.

    The only problem that I can see is that S&F forms require a results url, which would be different for each page. I cannot see how you would get around this.

    #82027

    Anonymous
    Inactive

    Hi Ross,

    Thanks for getting back to me on this.

    Unfortunately i can’t share a link to the site at the moment as i’m working on it locally but i will try and upload it live somewhere today so you can have a look at it.

    And yes, it displays the posts associated with the $post->ID correctly when you first go to the page and also shows the search options for just those posts. It’s when i make a search it then defaults back to all posts 🙁

    However, if i don’t include an if statement and just use the code below it then shows the posts under the $post->ID 54.

    function filter_function_name( $query_args, $sfid ) {
    	global $post;
    		  if($sfid==42) {
    				  $query_args = array (
    					'post_parent__in' => array('54'),
    				  );		   
    			}
    			
    	  return $query_args;
    	}
    add_filter( 'sf_edit_query_args', 'filter_function_name', 10, 2 );
Viewing 10 results - 91 through 100 (of 123 total)