Forums Forums Search & Filter Pro Adding custom functions to S&F filtering

Viewing 8 posts - 1 through 8 (of 8 total)
  • Trevor
    #269961

    I think what you want is the filter function that allows you to do the same to our query, which is this:

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    Anonymous
    #269971

    Thanks maybe that the thing, but I am not very expert and I don’t know how to use it.

    If I modified the function you suggest and I var_dump the results, I find exactly the list of post I should have, but still the filter doesn’t work

    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==225)
    	{
    	$posts = get_posts($query_args);
    	$today_year = date('yy');
    	$two_years_ago = $today_year - 2;
    	$current = array();
    
    		foreach( $posts as $post ) {
    			$meta = get_post_meta($post->ID);
    
    				$acf_year = $meta['anno'][0];
    				if($acf_year < $two_years_ago) {
    				$current[] = $post->ID;
    
    		}
    	}
    	$query_args = $current;
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    Could you help through it?

    Trevor
    #270011

    What is the form/post ID of your form?

    Anonymous
    #270013
    This reply has been marked as private.
    Trevor
    #270043

    I see that the form ID is 243 on that page, but your code uses 225?? Try changing those instances in the code.

    Anonymous
    #270052

    Sorry I already did it, but forgot to change it in the message to you. Still it doesn’t work.

    There is an alternative solution, which actually I do not like too much (I tested it on my local website). I display the results in a the custom post type archive page -> that is not affected by the function avia_post_slide_query_mod, thus results are fine. To avoid showing wrong “year” posts I added a specific condition to the S&F form setup under the post meta tab. However this is not a good solution, as the condition should be manually reset every year (there is not a way to automatically define it on the timestamp year). Also, I do not like too much results being displayed in another page.

    Hence, I would like to understand how can I force the S&F ajax call on the form taking in consideration that the search and filtering must be done only on displayed posts that are under the condition acf_field year < 2 years from timestamp year

    thanks

    Trevor
    #270109
    This reply has been marked as private.
    Ross Moderator
    #270521
    This reply has been marked as private.
Viewing 8 posts - 1 through 8 (of 8 total)