• Resolved mkormendy

    (@mkormendy)


    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=17

    This 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>

    https://wordpress.org/plugins/events-manager/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    you can try the last snippet shared by Marcus from this thread – https://wordpress.org/support/topic/em-with-wp_query-and-orderby-date?replies=15

    Thread Starter mkormendy

    (@mkormendy)

    Actually that was another reference of a script I already tried that did not work.
    In that case, I copied and pasted Marcus’s exact code and the outcome was in this order:

    • “Not So Classic” Golf Tournament – 2015-10-02
    • CTAC’s Annual Base Ball Banquet – 2015-10-22
    • D & G 4-D Barrel Race – 2015-09-25
    • Duncan Little Theatre’s – 2015-11-13
    • Duncan Little Theatre’s – 2016-02-19
    • Duncan Little Theatre’s “Becky’s New Car” – 2015-09-18
    • Duncan Little Theatre’s Miracle on 34th Street – 2015-11-13
    • Duncan’s Little Theatre presents – 2016-02-19
    • National Swine Registry Fall Classic Hog Conference – 2015-11-18
    • Prairie Circuit Finals Rodeo – 2015-10-15
    • Simmons Center Fall Festival Craft Fair – 2015-09-25

    As you can see, the order is alphabetical by the first letter.

    Thread Starter mkormendy

    (@mkormendy)

    I have resolved my problem .. I found this piece of code in my theme was sorting all of my custom post types alphabetically.

    function modify_query_order( $query ) {
        if ($query->is_tax() || (!$query->is_post_type_archive() && !$query->is_post_type_archive())) {
            $query->set( 'orderby', 'title' );
            $query->set( 'order', 'ASC' );
        }
    }
    add_action('pre_get_posts', 'modify_query_order');
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Custom Event Loop, Orderby not working’ is closed to new replies.