I need to order some custom post types alphabetically. I’ve added a value to elementor loop grid to set a custom query that I can intercept inside my functions.php file. I named it custom_charts
. As I know I can then modify the output of elementor by using the elementor/query/custom_charts
so at the moment I have this code
function custom_chart_sorting($query){
$query->set('post_type', 'tracks');
$query->set('meta_key', 'track_position'); //This is a custom field I've added with ACF to do the sorting but maybe there is a best way
$query->set('orderby', 'meta_value_num');
$query->set('order', 'ASC');
}
The query at the moment works fine, but how I can avoid to repeat the $query->set()
and is there a better way to alpabetically order my cpt when the query is executed and posts retrived?