Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Stephen Harris

    (@stephenharris)

    That would be ordering ‘asc’, no?

    If you want to show only future events, then you can do:

    $query->set( 'event_start_after', 'now' );
    Thread Starter andersss9

    (@andersss9)

    This does the job

    $query->set( 'event_start_after', 'now' );
    $query->set('order','desc');
          }

    but I would like to show the past events as well

    Plugin Author Stephen Harris

    (@stephenharris)

    Well you can remove the ‘event_start_after’, or perform a second query for only pas events

    $query->set( 'even_start_before', 'now' );
    Thread Starter andersss9

    (@andersss9)

    I just don’t get it working like I want it to be.

    My idea was to show the next occuring event first; June 20. Then scrolling down would be the events in an ascending order (21,22,23..). Then clicking right at the bottomo of the page you would get more “newer” (24,25..) events, clicking left you would get already occured events in a descending order (19,18,17..)

    Plugin Author Stephen Harris

    (@stephenharris)

    Well I think what you’re after is to display all events in chronological order, but to jump the user to the page where the next event happens.

    That’s possible, in which case remove

    $query->set( ‘even_start_before’, ‘now’ );

    You’d then need to intercept whenever that the “paged” attribute the query is not set. (If it’s set, do nothing). And then work out the page the next event is on.

    You can do that by querying all events are until the “next” is on. And dividing that number of events by the events per page.

    I seem to remember answering a similar request on the forums, but unfortunately these forums don’t lend themselves to searches :/.

    Thread Starter andersss9

    (@andersss9)

    That is exactly what I mean, and I got it working with this

    add_action('pre_get_posts','wpse50761_alter_query',15);
    function wpse50761_alter_query($query){
          if( $query->is_main_query() && ('event') ){
    $query->set('order','desc');
    
          }
    }
    add_action( 'pre_get_posts', 'myprefix_jump_to_current', 15 );
    function myprefix_jump_to_current( $query ){
    
        global $wp_query, $wp_rewrite;
    
        $paged = (int) $query->get('paged');
    
        if( eventorganiser_is_event_query( $query ) && $query->is_main_query() && ( $paged == 0 ) ){
    
            $events = eo_get_events( array( 'fields'=>'ids', 'event_start_before' => 'now', 'posts_per_page' => -1, ) );
    
            $per_page = absint( get_option('posts_per_page') );
            $pages = floor( ( count( $events ) + 1 ) / $per_page );
    
            if( $pages != 0 && $pages != 1 ){
                $query->set('paged', $pages );
            }
        }
    }

    well kind of… Now it’s breaking something so that some of my venue categories are showing “No venues found”, even if there are.

    Any ideas?

    Plugin Author Stephen Harris

    (@stephenharris)

    That’ll be cause your

    $events = eo_get_events( ... );

    query is for *all* events. So you’re finding which page the event is on when all events are listed, and not when events at that venue/category are listed.

    Basically you want to emulate the exact same query as the main query, with the additional ‘events before now’ part.

    I’ve not tried it, but replacing that with something like:

    $count_query = $query->query_vars;
     $count_query['event_start_before'] = 'now';
     $count_query['fields'] = 'ids';
     $count_query['posts_per_page'] = -1;
     $events = eo_get_events( $count_query );

    might work.

    Thread Starter andersss9

    (@andersss9)

    Perfect, it works!

    Thanks a lot!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Orderby the date’ is closed to new replies.