Forums Forums Search Search Results for 'sf_edit_query_args'

Viewing 10 results - 71 through 80 (of 175 total)
  • Author
    Search Results
  • #188232

    Anonymous
    Inactive

    I’m using the code bellow to hide posts that are older than the current date. It’s working on the default results but it’s not working on the filter(dropdown).

    Is there a way to exclude old posts from showing on the filter(Search Form UI) too?

    Thanks

    add_filter( ‘sf_edit_query_args’, ‘kp_exclude_old_post’, 100, 2 );
    function kp_exclude_old_post( $query ) {

    $time_ago = date(‘Y-m-d’, strtotime(‘-1 day’));

    $query[‘meta_query’] = array(
    array(
    ‘key’ => ‘acfDia’,
    ‘value’ => $time_ago,
    ‘compare’ => ‘>=’,
    ‘type’ => ‘DATE’
    )
    );

    return $query;
    }

    #188189

    Anonymous
    Inactive

    Hi Trevor,

    We are getting close 🙂

    It’s important that they are properly ranked. That’s why I used following hook to change the order:

    /* Change query Search and filter pro */
    function filter_function_name( $query_args, $sfid ) {
    	
    	if($sfid==1710)
    	{
    		//modify $query_args here before returning it
    		$query_args['meta_key'] = 'prioriteit_mandaat';
    		$query_args['orderby'] = 'meta_value_num';
    		$query_args['order'] = 'ASC';
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    
    #184825

    Anonymous
    Inactive

    Fair enough!

    Should anyone else have the same problem: I’ve managed to find a hacky but reasonable solution for now: when parsing the drop-down contents (like turning “last_quarter” into a start and an end date) I inject some JavaScript into the document that sets the dropdown to the right value.

    if (isset($_GET["_sfm_pseudofield_daterange"])) {
       
        $daterange = $_GET["_sfm_pseudofield_daterange"];
        ....  Handle the date stuff
    
        // Now remove the GET parameter so it doesn't get used as a filter and lead to 0 results
        unset($_GET["_sfm_pseudofield_daterange"]);
    
        // Use JavaScript to correctly set the dropdown again even though GET parameter was unset
        add_action( 'wp_head', function() use($daterange) {
           ?><script>jQuery(document).ready(function(){ jQuery("[name='_sfm_pseudofield_daterange[]']").val("<?= htmlentities($daterange);?>");});</script><?
    		} );
    }

    As a feature request, it would be awesome to have a new “empty” field type (Text field, dropdown, check box, etc.) that gets passed along with the rest of the form, plus a documented interface for altering query parameters in the sf_edit_query_args hook.

    #184347

    Ross
    Keymaster

    Hi Dan

    There appears to be a small typo in the code Trevor supplied, post__not_in needs to be an array –

    function filter_post__not_in( $query_args, $sfid ) {
    
    	//if search form ID = 264, the do something with this query
    	if($sfid==264) {
    		global $post;
    		$postid = $post->ID ;
    		$query_args['post__not_in'] = array($postid);
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_post__not_in', 20, 2 );

    Thanks

    #183979

    Trevor
    Participant

    Not if you have already specified that in the search form setup. You might have to do this:

    function filter_function_name( $query_args, $sfid ) {
    
    	//if search form ID = 264, the do something with this query
    	if($sfid==264) {
    		//modify $query_args here before returning it
    		// $query_args['somearg'] = 'newvalue';
    		global $post;
    		$postid = $post->ID ;
    		$query_args['post__not_in'] = $postid
    	}
    
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    #183922

    Trevor
    Participant

    Hi

    Would it not be:

    function filter_function_name( $query_args, $sfid ) {
    
    	//if search form ID = 264, the do something with this query
    	if($sfid==264) {
    		//modify $query_args here before returning it
    		// $query_args['somearg'] = 'newvalue';
    		$postid = get_the_ID();
    		$query_args['post__not_in'] = $postid
    	}
    
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    #183892

    Anonymous
    Inactive

    Hi,

    Below is the code snippet I have used but it doesn’t seem to be working. I get ‘No results found’. Can you see anything obviously wrong with it?

    function filter_function_name( $query_args, $sfid ) {
    
    	//if search form ID = 264, the do something with this query
    	if($sfid==264) {
    		//modify $query_args here before returning it
    		// $query_args['somearg'] = 'newvalue';
    		$postid = get_the_ID();
    		$query_args = array(
    			'post_type' => 'artist',
    			'post__not_in' => $postid,
    		);
    	}
    
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    #183569

    Anonymous
    Inactive

    Thank you both so much for your help, I really appreciate it!

    I would like for all of the events to show as normal, and have all the keyword, category etc filters work as normal, I just want to change the behaviour of the date filter.

    Once a date is selected I would like the results to only include events that occur on that date (which it does already), but to also show events that occur after that date.

    I’ve updated my previous query to this which I think should work, except that it seems the date filter’s original programming is overriding my meta query.

    function upcoming_events( $query_args, $sfid ) {
    
    	if ( $sfid == 72 ) {
    
    		if(isset($_GET['_sfm_start_date'])){
    			$dateField = $_GET['_sfm_start_date'];
    
    			$query_args['meta_query'] = array( 
    				array(
    					'key' => 'start_date', 
    					'value' => $dateField, 
    					'compare' => '>=', 
    					'type' => 'NUMERIC' 
    				)
    			);
    		}
    	}
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'upcoming_events', 20, 2 );

    By using the print_r($query_args); I am able to see that the query does run when a date is entered, except it seems to be ignored as it doesn’t have any effect on the results. The results still only show events that occur on the exact date which is entered.

    How do I go about overriding the date filters current programming?

    #183232

    Anonymous
    Inactive

    Ok, awesome! I took a stab at it today and I’ve written this which pretty much works backwards. It removes all the past events on page load and maintains that when using the keywords and category filter. Then when I enter in a date it reverts to showing just the events that happen on that date, nothing upcoming. Would you be able to help me alter it to achieve what I need? I’m also not sure how to pull the users input from the form, or how to check a specific field if it has been utilized. I apologize if I’ve gone completely down the wrong track!

    function upcoming_events( $query_args, $sfid ) {
    
    	if ( $sfid == 72 ) {
    		$dateField = ''; //get users input, if it exists
    
    		if ( $dateField != '' ) {
    
    			$query_args['meta_query'] = array( 
    				array(
    					'key' => 'start_date', 
    					'value' => $dateField, 
    					'compare' => '>=', 
    					'type' => 'NUMERIC' 
    				)
    			);
    		}
    	}
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'upcoming_events', 20, 2 );
    #183103

    In reply to: Show child posts only


    Anonymous
    Inactive

    Thank you! Here’s what worked for me, in case anyone needs it:

    function filter_function_name( $query_args, $sfid ) {
      
      if($sfid==22)
      { 
        $query_args['post_parent__not_in'] = array(0);
      }
      
      return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
Viewing 10 results - 71 through 80 (of 175 total)