order events by start date – working query
-
I’ve seen here a lot of topics about ordering events by start date. Unfortunately without answer. After a while I came up with working code. It is a Custom Select Query comining two tables. Showing posts that start_datetime is >= than current date and ordering ASC. Maybe it would help someone.
<?php global $wpdb; $date = date("Y-m-d"); $querystr = " SELECT * FROM wp_posts JOIN wp_ftcalendar_events ON wp_posts.ID = wp_ftcalendar_events.post_parent WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type = 'post' AND wp_ftcalendar_events.start_datetime >= '$date' ORDER BY wp_ftcalendar_events.start_datetime ASC "; $pageposts = $wpdb->get_results($querystr, OBJECT_K); ?> <?php if ($pageposts): ?> <?php global $post; ?> <?php foreach ($pageposts as $post): ?> <?php setup_postdata($post); ?> <?php $start_date = date_i18n("Y-m-d", strtotime( $post->start_datetime )); ?> <?php the_title(); ?><br> <?php echo $start_date; ?><br> <?php endforeach; ?> <?php endif; ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘order events by start date – working query’ is closed to new replies.