Forums Forums Search Search Results for 'sf_edit_query_args'

Viewing 10 results - 131 through 140 (of 175 total)
  • Author
    Search Results
  • #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 );

    Trevor
    Participant

    Right now, by default the plugin only sorts by the count excluding the children. I wonder if it is possible to modify the query using our Edit Query Arguments filter. It should be, if it can be done in general in WordPress.

    You might want to do a search in this forum for sf_edit_query_args orderby to see if there any code snippets. For example, I found this thread. Not the same question, but it does show another user has used this filter.

    #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.

    #93336

    In reply to: Meta sort order


    Ross
    Keymaster

    Hey Scott

    Is it possible you have a pre_get_posts somewhere in your theme, that may be jumping in / hijacking our sort order on the query?

    Have you tried sf_edit_query_args with a different priority so it runs later, like 2000?

    Thanks

    #92457

    In reply to: Post Meta Date Range


    Ross
    Keymaster

    Hi Max

    As I mentioned, I hadn’t tested the code, merely pointed out something you were doing wrong.

    You are adding a custom meta query, to our S&F query which is fine. But I am not able to validate if your meta query is correct or not.

    The sf_edit_query_args should work no problem, so I suggest the problem lies in your code (and possibly the specifics of your meta query).

    Why not create (seperate form all this S&F stuff), create a new WP_Query, with your meta query, and see if produces the desired results?

    https://codex.wordpress.org/Class_Reference/WP_Query

    The first example under “usage” should be fine, provided you set your post type and meta query in the $args.

    Once we know your meta query is correct and working properly we can have a look to see where the above is going wrong (please send me a link of it working).

    Thanks

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

    Anonymous
    Inactive

    Hi Trevor,

    Have you been able to forward this message to the developer yet?

    I have realised there is another method i could try to achieve what i want but this would require to create multiple search forms and then target their IDs individually using the sf_edit_query_args function.

    I understand the developer is a busy man and i don’t want to be a pest but are you able to give an estimated time for when you think he’ll get a chance to look at it?

    This is for a project i’m working on for a client in which the deadline is at the end of the month so if the waiting list is long then i don’t mind going for the alternative method.

    Many thanks

Viewing 10 results - 131 through 140 (of 175 total)