Hi,
I made this filter to sort a Posts module (custom query) by ACF Date, which seems to be not supported by BB Posts module “Sort by Meta value” option.
The idea is to sort Events by event date set in a custom field.
It seems to work fine but i’m not sure of the code and syntax, maybe it could be enhanced.
add_filter( 'fl_builder_loop_query_args', 'posts_grid_acf_date_filter' );
function posts_grid_acf_date_filter( $query_args ) {
// Apply filter on specific Posts module (by ID)
if ( 'av-events-grid' == $query_args['settings']->id ) {
// Sort Posts by ACF Date
$query_args['orderby'] = 'meta_value';
$query_args['meta_key'] = 'posts_event_date';
$query_args['order'] = 'DESC';
}
return $query_args;
}
Thanks for your advice!