Forums › Forums › Search & Filter Pro › Altering programmatically Search and Filter Pro default settings
- This topic has 4 replies, 3 voices, and was last updated 6 years, 5 months ago by Ross.
-
Anonymous(Private) May 23, 2018 at 4:30 pm #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.
Ross Moderator(Private) June 7, 2018 at 10:54 pm #180043Hi 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?
-
AuthorPosts