Put these functions in your theme’s functions.php file: https://gist.github.com/keesiemeijer/7563447
Get the dates for your meta query like so:
// example current month
$date_args = array(
'type' => 'month', // month - year, month, day
'start_from' => 'type', // today, type - Start from today, or from first/last day of month/year
'future_past' => 'past', // past, future - Past or future date range
'offset' => 0, // 0 = current month (1 = one month from start date etc...)
'duration' => 1, // duration of 1 month (1 or higher)
);
// get the BETWEEN dates
$dates = get_between_clause_dates( $date_args );
$args= array(
'post_type' => array( 'page' ),
'posts_per_page' => 2,
'meta_key' => 'data-lansare',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'data-lansare',
'value' => $dates,
'compare' => 'BETWEEN',
'type' => 'DATE',
)
)
);
If you set the ‘start_from’ parameter to ‘type’ you get whole months (or years). The result of the get_between_clause_dates() function in the code above (on November 20 2013) is:
array( '2013-11-01', '2013-11-30' )
With ‘start_from’ set to ‘today’ the date starts at the current date.
// example on November 20 2013
$date_args = array(
'type' => 'month', // month - year, month, day
'start_from' => 'today', // today, type - Start from today, or from first/last day of month/year
'future_past' => 'past', // past, future - Past or future date range
'offset' => 0, // 0 = current month (1 = one month from start date etc...)
'duration' => 1, // duration of 1 month (1 or higher)
);
$dates = get_between_clause_dates( $date_args );
Results in in an array like this:
array( '2013-10-20', '2013-11-20' )
Here are the args if you want the next full month (use an offset):
// example on November 20 2013
$date_args = array(
'type' => 'month', // month - year, month, day
'start_from' => 'type', // today, type - Start from today, or from first/last day of month/year
'future_past' => 'future', // past, future - Past or future date range
'offset' => 1, // 0 = current month (1 = one month from start date etc...)
'duration' => 1, // duration of 1 month (1 or higher)
);
Which results in:
array( '2013-12-01', '2013-12-31' )
Example of getting the current year and the year before:
// example on November 20 2013
$date_args = array(
'type' => 'year', // month - year, month, day
'start_from' => 'type', // today, type - Start from today, or from first/last day of month/year
'duration' => 2, // duration of 1 month (1 or higher)
// don't need to set all parameters (see defaults of the function)
);
Which results in:
array( '2012-01-01', '2013-12-31' )
I hope this makes sense.