Sort posts by the day rather than chronological
-
I am building a simple birthday plugin for a client. It is a custom post type that takes the title as the name of the person and the post date as the date of birth. It then filters the posts to show only the birthdays of the current month. My problem is the posts are being sorted chronologically rather than by the day of the month for example: if John Smith was born 1/17/1968 he would show up BEFORE Luise Reynolds who is born 1/3/1992 where I would prefer the list be sorted by the day, that is ‘3’ coming before ’17’ here is my code below.
$args = array( 'post_type' => 'birthdays', 'orderby' => 'date', 'order' => 'ASC' ); $birthdays = new WP_Query($args); if($birthdays->have_posts()){ while ($birthdays->have_posts()){ $birthdays->the_post(); $current_date = date('m'); $post_date = get_the_time('m'); $age = date('Y') - get_the_time('Y'); if($current_date==$post_date){ ?> <div style="padding:50px"> <h2 style="font-size:24pt;"><?php the_title()?></h2> <h3 style="font-size:18pt;"><em>is turning <?php echo $age;?> on the <?php echo get_the_time(jS);?></em></h3> </div> <?php } } }else{ echo 'No birthdays entered yet!'; }
I’m sort of new to making plugins so any help would be much appreciated! Thanks!
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Sort posts by the day rather than chronological’ is closed to new replies.