Thanks esmi. I know this could be complicated and I need a little more explanation.
In my example structure could be simple like this:
id title custom_field field_value (DD.MM.YYYY)
-------------------------------------------------------------------
1 course 1 date_from_1 01.08.2011
1 course 1 date_from_2 01.09.2011
1 course 1 date_from_3 01.10.2011
2 course 2 date_from_1 05.09.2011
3 course 3 date_from_1 10.09.2011
3 course 3 date_from_2 10.10.2011
Each “educational_course” post type could have one or more date_from_x defined. Now I need to loop ALL dates no matter the course was already queried before by another date. One course should be multiple times in the loop if it has more than one valid date_from_x fields.
The final output echo on page should look like this:
Calendar
--------
01.08.2011 - course 1
01.09.2011 - course 1
05.09.2011 - course 2
10.09.2011 - course 3
01.10.2011 - course 1
10.10.2011 - course 3
What steps should I do to achieve that?
1) Select all posts in one or more queries
I think the code below can’t do it. It will select portfolio posts that have BOTH dates not empty, right?
$args = array(
'post_type' => 'educational_course',
'meta_query' => array(
array(
'key' => 'date_from_1',
'value' => '',
'type' => 'date',
'compare' => '!='
),
array(
'key' => 'date_from_2',
'value' => '',
'type' => 'date',
'compare' => '!='
),
... // other date_from_X
)
);
$query = new WP_Query( $args );
So I think it will be needed to join multiple queries via filters of wp_query like “posts_join” or “posts_orderby”. Unfortunately there is a lack of documentation how to do that, see https://codex.www.ads-software.com/Function_Reference/WP_Query.
2) Reorder the data acording to date_from_x field.
A hard task. Really don’t know how to do that since there are more keys.