I have a loop that returns a list of birthdays. Currently, I'm using orderby => meta_value_num sort and it sorts year as well. See the code below:
$today = date('d');
$tomorrow = date('d', strtotime('+ 1 day'));
$thedayaftertomorrow = date('d', strtotime('+ 2 day'));
$current_month = date('m');
$next_month = date('m', strtotime('+ 1 month'));
$args = array (
'posts_per_page' => 4, // number of posts
'post_type' => 'employees', // your custom post type
'meta_key' => 'birthday', // your custom date field name
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'birthday',
'compare' => 'REGEXP',
'value' => '[0-9]{4}' . $current_month . $today,
),
array(
'key' => 'birthday',
'compare' => 'REGEXP',
'value' => '[0-9]{4}' . $current_month . $tomorrow,
),
array(
'key' => 'birthday',
'compare' => 'REGEXP',
'value' => '[0-9]{4}' . $current_month . $thedayaftertomorrow,
),
array(
'key' => 'birthday',
'compare' => 'REGEXP',
'value' => '[0-9]{4}' . $next_month . '[0-9]{2}',
),
)
);
Is there a way to ignore year and order by month and day? Date format I'm using is: Ymd
The code returns the following:
1990-12-01 1992-01-04 2001-03-04 2005-06-07