Custom Event Loop, Orderby not working
-
I am trying to make my own custom loop of events with special row demarcations, and I have tried to use many different argument combinations with the new WP_query object, just to get it to sort future events from immediate to later in the future.
Unfortunately, the order keeps sorting it by name. I have looked at the following posts, and tried their different argument structures to no avail:
(Agelonwl example) https://wordpress.org/support/topic/custom-query-ignores-scopefuture
(Marcus example) https://wordpress.org/support/topic/infinite-scroll-6?replies=17This is my code block:
<div class="pad group"> <h1 class="post-title">Upcoming Events</h1> <?php $args = array('post_type' => 'event', 'orderby' => 'event_start_date', 'order' => DESC ); $events_query = new WP_Query( $args ); ?> <?php if ( $events_query->have_posts() ) : ?> <div class="post-list group"> <?php $i = 1; echo '<div class="post-row">'; while ( $events_query->have_posts() ): $events_query->the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class('group post'); ?>> <div class="post-inner post-hover"> <div class="post-thumbnail"> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> <?php if ( has_post_thumbnail() ): ?> <?php the_post_thumbnail('thumb-medium'); ?> <?php elseif ( ot_get_option('placeholder') != 'off' ): ?> <img src="<?php echo get_template_directory_uri(); ?>/img/thumb-medium.png" alt="<?php the_title(); ?>" /> <?php endif; ?> <?php if ( has_post_format('video') && !is_sticky() ) echo'<span class="thumb-icon"><i class="fa fa-play"></i></span>'; ?> <?php if ( has_post_format('audio') && !is_sticky() ) echo'<span class="thumb-icon"><i class="fa fa-volume-up"></i></span>'; ?> <?php if ( is_sticky() ) echo'<span class="thumb-icon"><i class="fa fa-star"></i></span>'; ?> </a> <?php if ( comments_open() && ( ot_get_option( 'comment-count' ) != 'off' ) ): ?> <a class="post-comments" href="<?php comments_link(); ?>"><span><i class="fa fa-comments-o"></i><?php comments_number( '0', '1', '%' ); ?></span></a> <?php endif; ?> </div><!--/.post-thumbnail--> <div class="post-meta group"> <p class="post-category"><?php the_category(' / '); ?></p> <p class="post-date"><?php get_post_meta($post_id, '_event_start_date', true); ?></p> </div><!--/.post-meta--> <h2 class="post-title"> <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a> </h2><!--/.post-title--> <?php if (ot_get_option('excerpt-length') != '0'): ?> <div class="entry excerpt"> <?php the_excerpt(); ?> </div><!--/.entry--> <?php endif; ?> </div><!--/.post-inner--> </article><!--/.post--> <?php if($i % 2 == 0) { echo '</div><div class="post-row">'; } $i++; endwhile; echo '</div>'; ?> </div><!--/.post-list--> <?php get_template_part('inc/pagination'); ?> <?php endif; ?> </div>
The topic ‘Custom Event Loop, Orderby not working’ is closed to new replies.