order_by Custom Date
-
Hey guys,
Have a perplexing problem. Im trying to get some events going with custom start and end dates as custom fields. They both use the format ‘YYYYMMDD’. The problem I have is that the code seems to work fine on one tab, but starts ordering the posts randomly on the next few. I copied and pasted the code exactly.
<!-- Tabs for current month --> <?php $dateM = date('m'); $dateY = date('Y');// Current Year $args = array('post_type' => 'events', 'numberposts' => '5', 'order_by' => 'event_start','order' => 'asc', 'meta_query' => array( 'relation' => 'AND', array('key'=>'Event Month Start', 'value' => $dateM, 'compare' => '=', 'type' => 'NUMERIC'), array ('key'=>'Event Year Start', 'value' => $dateY, 'compare' => '=', 'type' => 'NUMERIC') ) ); $recent_posts = get_posts($args); foreach($recent_posts as $recent) : setup_postdata($recent); $image = wp_get_attachment_image(get_post_thumbnail_id($recent->ID),'events-loop'); $event_start_S = get_post_meta($recent->ID,'event_start',true); $event_start = date('j F Y', strtotime($event_start_S)); $event_end_S = get_post_meta($recent->ID,'event_end',true); $event_end = date('j F Y', strtotime($event_end_S)); ?> <article> <div class="pic"><a href="<?php echo get_the_permalink($recent);?>" class="w_hover img-link img-wrap"><?php echo $image; ?><span class="link-gallery"></span> </a> </div> <h3><a href="<?php echo get_the_permalink($recent); ?>"><?php echo get_the_title($recent); ?></a></h3> <ul class="icons"> <li><a href="<?php echo get_the_permalink($recent); ?>" class="post_date"><?php echo $event_start;?> - <?php echo $event_end;?></a></li> <li><a href="" class="comments_count"></a></li> </ul> <div class="text"><?php echo get_excerpt(120,$recent); ?></div> </article> <?php endforeach; wp_reset_postdata(); ?>
That is the code for the current month and this:
<!-- Tabs for current month --> <?php $dateM = date('m')+5; $dateY = date('Y')+1;// Set the Year 1 year ahead, i have a switch statement here to check $args = array('post_type' => 'events', 'numberposts' => '5', 'order_by' => 'event_start','order' => 'asc', 'meta_query' => array( 'relation' => 'AND', array('key'=>'Event Month Start', 'value' => $dateM, 'compare' => '=', 'type' => 'NUMERIC'), array ('key'=>'Event Year Start', 'value' => $dateY, 'compare' => '=', 'type' => 'NUMERIC') ) ); $recent_posts = get_posts($args); foreach($recent_posts as $recent) : setup_postdata($recent); $image = wp_get_attachment_image(get_post_thumbnail_id($recent->ID),'events-loop'); $event_start_S = get_post_meta($recent->ID,'event_start',true); $event_start = date('j F Y', strtotime($event_start_S)); $event_end_S = get_post_meta($recent->ID,'event_end',true); $event_end = date('j F Y', strtotime($event_end_S)); ?> <article> <div class="pic"><a href="<?php echo get_the_permalink($recent);?>" class="w_hover img-link img-wrap"><?php echo $image; ?><span class="link-gallery"></span> </a> </div> <h3><a href="<?php echo get_the_permalink($recent); ?>"><?php echo get_the_title($recent); ?></a></h3> <ul class="icons"> <li><a href="<?php echo get_the_permalink($recent); ?>" class="post_date"><?php echo $event_start;?> - <?php echo $event_end;?></a></li> <li><a href="" class="comments_count"></a></li> </ul> <div class="text"><?php echo get_excerpt(120,$recent); ?></div> </article> <?php endforeach; wp_reset_postdata(); ?>
The first query works and I can put the query on different tabs and it’ll work fine with the dates in order. The other tabs won’t even show the posts or would randomly order them and not order them. Please help.
Regards
Zayd
Viewing 13 replies - 1 through 13 (of 13 total)
Viewing 13 replies - 1 through 13 (of 13 total)
- The topic ‘order_by Custom Date’ is closed to new replies.