I would like to build one big query that is sorted by 2 custom fields (type date).
I have a query that needs to have 2 post types ['track_trip', 'training']
. Those 2 types have ACF custom fields that stand for future dates. ['date_track', 'date_training']
. How should I combine my query to sort those types based on a custom field? Both are date type of course.
new WP_Query([
'post_type' => ['tourist_trip', 'training'],
'post_status' => 'publish',
'meta_key' => 'date_tourist', ??
'orderby' => 'meta_value',
'order'=> 'ASC'];
])
Thanks guys for tips. I was able to solve it.
$args_track = [
'post_type' => ['track_trip', 'training'],
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'OR',
'date_track_sort' => array(
'key' => 'date_track',
'type' => 'DATE'
),
'date_training_sort' => array(
'key' => 'date_training',
'type' => 'DATE'
),
) ,
'orderby' => ['date_track_sort' => 'ASC', 'date_training_sort' => 'ASC']];
```
meta_query
parameter yet? There are a lot of parameters and examples documented at the official WP dev docs forWP_Query
at developer.wordpress.org/reference/classes/wp_query/… including how to query meta fields and how to sort things. Your meta values will need to be in a particular format though, and if they aren't in that format you will need to contact ACF support or ask other ACF users how to fix that for your fields ( ACF/3rd party plugin support is offtopic here )