Filter: bricks/query_filters/sort_query_vars
Filters the query variables generated by an active “Sort” filter element. This allows you to implement custom sorting logic (e.g., sorting by a custom meta key or a calculated value).
Parameters
Section titled “Parameters”$query_vars(array): TheWP_Queryarguments generated by the sort filter (e.g.,['orderby' => '...', 'order' => '...']).$filter(array): The active filter data, including selected sort option.$query_id(string): The ID of the query loop being sorted.$filter_index(int): The index of this filter in the active filters list.
Example usage
Section titled “Example usage”add_filter( 'bricks/query_filters/sort_query_vars', function( $query_vars, $filter, $query_id, $filter_index ) { // Example: Custom sort by 'popularity' if ( $filter['value'] === 'popularity' ) { $query_vars['orderby'] = 'meta_value_num'; $query_vars['meta_key'] = 'post_views_count'; $query_vars['order'] = 'DESC'; }
return $query_vars;}, 10, 4 );Was this helpful?
A quick vote and short notes help us improve these docs faster.
Leave a note for us
Please do not include passwords, license keys, or personal data. We store submitted notes to improve the docs.
Thanks for sharing feedback. We're using it to improve these docs.