From cbd728c37d8d7cb428e9c4ed1382c6e619347f8b Mon Sep 17 00:00:00 2001 From: Ian Jenkins Date: Wed, 19 Dec 2018 16:41:14 +0000 Subject: [PATCH] Search: Add a hook on returning filters. (#10706) I recently had a use case where I wanted to add custom filters (i.e. not a taxonomy, post type or date histogram) and found I could set the filter no problem but get_filters would ignore it as it wasn't supported. I'd like to be able to easily support custom filters through a hook into get_filters(). --- modules/search/class.jetpack-search.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/search/class.jetpack-search.php b/modules/search/class.jetpack-search.php index f44f9770f49e1..8d2031c2f42db 100644 --- a/modules/search/class.jetpack-search.php +++ b/modules/search/class.jetpack-search.php @@ -1610,7 +1610,20 @@ public function get_filters( WP_Query $query = null ) { } // End foreach(). } // End foreach(). - return $aggregation_data; + /** + * Modify the aggregation filters returned by get_filters(). + * + * Useful if you are setting custom filters outside of the supported filters (taxonomy, post_type etc.) and + * want to hook them up so they're returned when you call `get_filters()`. + * + * @module search + * + * @since 6.9.0 + * + * @param array $aggregation_data The array of filters keyed on label. + * @param WP_Query $query The WP_Query object. + */ + return apply_filters( 'jetpack_search_get_filters', $aggregation_data, $query ); } /**