Support Forums

Hey there, it looks like you've been redirected from designsandcode.com - as you can see we have a new home - read more

Looking for support? You can access the support system via your account.

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

Viewing 5 posts - 1 through 5 (of 5 total)
  • PABLO LIZ
    #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.

    PABLO LIZ
    #179266

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

    Trevor Moderator
    #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)

You must be logged in to reply to this topic.