order of events: showing events by post date

Home Forums Calendar Products Community Events order of events: showing events by post date

Viewing 10 posts - 16 through 25 (of 25 total)
  • Author
    Posts
  • #1074678
    Josh
    Participant

    Hey Marion,

    I apologize for the delay here and I appreciate your patience.

    I hit a wall trying to get this to work from a bunch of different perspectives. Like Edison, I found a bunch of ways that failed but eventually, with the help from others on our team, I found the orderby post date “bamboo”.

    The issue here came down to a recently modified function and forcing all “tribe_events” queries to use the event date for ordering no matter watch you may have set or filtered it to be.

    To get this to work though, would be to modify your current approach slightly. Rather than redirect to the default list view (since there is a lot more going on there than just an events query) it would be best to do a new custom “tribe_events_query” using the following args:

    
    $args = array(
       'suppress_filters' => true,
       'post_type' => 'tribe_events',
       'orderby' 	=> 'date',
       'order' 	=> 'DESC'
    );
    

    From there, you can do a foreach loop on the returned array and apply your Masonry code to that loop there.

    Let me know if this helps.

    Thanks!

    #1075074
    Marion
    Participant

    Hi Josh.

    thank you so much for your research and new solution! I will get into it by tomorrow and let you know if it works!

    Marion

    #1078353
    Josh
    Participant

    Hey Marion,

    No problem! Let me know how it turns out.

    Thanks!

    #1082680
    Marion
    Participant

    Hi Josh,

    this is my new code:

    <?php 
    global $post;
    
    $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
    
          $all_events = tribe_get_events(array(
          'suppress_filters' => true,
          'post_type' => 'tribe_events',
          'order'    => 'DESC',
          'posts_per_page' => 30,
          'paged' => $paged,
          'page' => $paged
        ));
    
    foreach($all_events as $post) { 
    		setup_postdata($post);
    ?>
    
    <!-- the loop -->
    <article class="grid-item">
    ...
    <a href="<?php echo esc_url( tribe_get_event_link() ); ?>" class="tribe-events-read-more" rel="bookmark"><?php esc_html_e( 'Find out more', 'the-events-calendar' ) ?> &rang;</a>
    </article>
    <!-- end of the loop -->
        
    <?php } //endforeach ?>
    <?php wp_reset_query(); ?> 
    

    Is it the way you were talking about?
    And I think it its working like I want, still have to to some testing.

    But ( I am sorry, that there is another but): is it possible only to query the future events?

    Have a nice weekend
    Marion

    #1083664
    Josh
    Participant

    Hey Marion,

    That looks like it should work! Also, to have it show only the upcoming, you can add “eventDisplay => ‘upcoming'” to the args there.

    Let me know if this helps.

    Thanks!

    #1083766
    Marion
    Participant

    Hi Josh,

    unfortunately this does not work:

    <?php 
    global $post;
    
    $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
    
    	  $all_events = tribe_get_events(array(
    	  'eventDisplay'=>'upcoming',
      	  'suppress_filters' => true,
          'post_type' => 'tribe_events',
          'order'    => 'DESC',
          'posts_per_page' => 30,
          'paged' => $paged,
          'page' => $paged
        ));
    
    foreach($all_events as $post) { 
    		setup_postdata($post);
    ?>
    
        <!-- the loop -->

    When I erase ‘suppress_filters’ => true it works, but then again the order is not the way I want it to be (by post date not event date).

    I really like to solve this, any more ideas?

    Kind regards Marion

    #1084260
    Josh
    Participant

    Hey Marion,

    Hmm, you’re right. I didn’t consider that but if we are suppressing filters then it is unlikely that any of our args for the query would continue to work such as the eventDisplay one.

    The alternative would be to do a check just inside your foreach loop between the current date and the event start date. If the event start date is greater than the current date then display the event.

    Let me know if this helps.

    Thanks!

    #1084437
    Marion
    Participant

    .. it seemed actually just an easy request and it turned out to be so tricky đŸ˜‰

    Do you have a kind of an example link/snippet? That would be great…

    Thank you Josh,
    Marion

    #1085452
    Josh
    Participant

    Hey Marion,

    I don’t currently have a snippet on hand. When adding to your template though, you’ll use the Date link above to get the current date and you can use “tribe_get_start_date” for the event date. The comparison would then be a normal “if” statement (if( $start_date > $date)).

    Thanks!

    #1091396
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 10 posts - 16 through 25 (of 25 total)
  • The topic ‘order of events: showing events by post date’ is closed to new replies.