Ordering (Sorting) Custom Queries

'posts_per_page' => -1, // (-1) will display All
'post_type' => 'event',
'orderby' => 'post_date', //Default
'orderby' => 'title',
'orderby' => 'rand',
'order' => 'ASC'

$homepageEvents = new WP_Query(array(
'posts_per_page' => 2,
//Get the new post_type here
//This has been registered on wp-content/mu-plugins new folder
'post_type' => 'event',
'orderby' => 'post_date'
));

while($homepageEvents->have_posts()){
  $homepageEvents->the_post(); ?>
  <div class="event-summary">
    <a class="event-summary__date t-center" href="<?php the_permalink(); ?>">
      <span class="event-summary__month">
      <?php $eventDate = new DateTime(get_field('event_date'));
        echo $eventDate->format('M')
      ?>
      </span>
      <span class="event-summary__day">
      <?php 
      echo $eventDate->format('d') 
      ?>
      </span>
    </a>
    <div class="event-summary__content">
      <h5 class="event-summary__title headline headline--tiny"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
      <p><?php if (has_excerpt()) {
                // the_excerpt(); outputs some html p tag that we don't want so we go for: echo get_the_excerpt();
                //the_excerpt();
                echo get_the_excerpt();
              } else {
                echo wp_trim_words(get_the_content(), 10); 
              } ?> <a href="<?php the_permalink(); ?>" class="nu gray">Read more</a>
      </p>
    </div>
  </div>
<?php } wp_reset_postdata();
?>
Scroll to Top