So this may not exactly answer the question, but I hope it could help you, particularly with the following part in the question:
I just want the oldest/ lesson-001, 002 etc.
As I pointed in the comments, if the “lessons”/posts are dated chronologically like in the diagram (Jan 1st, Jan 14th, Feb 1st, etc.), you could just use the date query in WP_Query
and query for posts dated after the start_date
value and up until today’s date.
So if for example the start_date
is 2020-01-01
(i.e. January 1st 2020) and today was February 1st 2020, the following query would return the January 1st
, January 14th
and February 1st
posts, which I suppose is what you wanted based on the question:
$args = array(
'post_type' => 'lesson',
'orderby' => 'date', // Note that 'date' is simply an alias for 'post_date'.
'order' => 'DESC',
'date_query' => array(
'after' => '2019-12-31', // this is start_date; equivalent to '2019-12-31 23:59:59'
'before' => 'tomorrow', // equivalent to using the value '2020-02-02 00:00:00'
),
);
$query = new WP_Query( $args );
// ... your code here ...
Note: The after
and before
parameters in the date query, they both accept a value that strtotime()
accepts (e.g. tomorrow
, yesterday
, +1 month
, etc.). Also, in WP_Query
, date
is the default orderby
value, while DESC
is the default order
value.