Altering programmatically Search and Filter Pro default settings

Forums › Forums › Search & Filter Pro › Altering programmatically Search and Filter Pro default settings

Viewing 5 posts – 1 through 5 (of 5 total)
  • Anonymous
    #179263

    We are in the need to customize a bit more the criteria for fetching using dynamic information during the searches.
    We are looking for altering the query posts arguments to exclude some posts from the search.

    But basically the process of selection of those posts are dynamic and we can’t built it using the UI.
    Example:

    Exclude post which custom meta field ‘ListDate’ is older than two months.

    The following code kind of works but leaves all complex filtering counts unaltered in the dropdown filters we have.
    Is there a way to make the dropdown filters created to be aware of this update?

    
    add_filter( 'sf_edit_query_args', 'kp_exclude_sold_older_than_two_months', 100, 2 );
    function kp_exclude_sold_older_than_two_months( $query ) {
    
    	$time_ago = date('Y-m-d', strtotime('-2 months'));
    
    	$query['meta_query'] = array( 
    	    array(
    		        'key' => 'ListDate', 
    		        'value' => $time_ago, 
    		        'compare' => '>=', 
    		        'type' => 'DATE' 
    	        )
            );
    
    	return $query;
    }
    

    Thanks in advance.

    Pablo.

    Anonymous
    #179266

    Also trying this statically with a date > ‘20180323’ in the meta default settings leaves the dropdown filter counts unaltered.

    Trevor
    #179273
    This reply has been marked as private.
    Ross Moderator
    #180043

    Hi Pablo

    Apologies for the delay coming back.

    Our filter, sf_edit_query_args is meant especially for this reason, so your changes are reflected across our fields.

    I just did a quick test, with a different meta query (using price, on my shop) and it worked exactly as expected, with all the fields updating their count numbers:

    add_filter( 'sf_edit_query_args', 'kp_exclude_sold_older_than_two_months', 100, 2 );
    function kp_exclude_sold_older_than_two_months( $query ) {
    	
    	$query['meta_query'] = array( 
    		array(
    			'key' => '_price', 
    			'value' => 11, 
    			'compare' => '>=', 
    			'type' => 'NUMERIC' 
    		)
    	);
    	return $query;
    }

    The only thing is, some fields, such as post type, don’t have a dynamic count, so would remain unaffected regardless.

    Could this be the issue you are seeing?

    Ross Moderator
    #180044
    This reply has been marked as private.
Viewing 5 posts – 1 through 5 (of 5 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.