• Resolved tarik916

    (@tarik916)


    Hi! I’m using the default archive page to display the events and have altered the query to have a second page to show past events. When a past event is clicked, a 404 error is returned. Is there any way to override this code so past events can be viewed?

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Guido

    (@guido07111975)

    Hi,

    I don’t know why a 404 is returned, normally the single event page opens and this is similar to how a default post opens. Do you have a link to your archive page? But first you can save your permalink again and see what happens.

    Besides this, I don’t recommend using default archive pages because events are not ordered by event date on these pages.

    Guido

    Thread Starter tarik916

    (@tarik916)

    Thanks for the response. It turns out my custom code to alter the archive query did not include !is_singular(), so it was trying to display query results on the details page, causing the error.

    For the default archive, I used pre_get_posts to do the following.

    $meta_query = array(
                'relation' => 'AND',
                array(
                    'key' => 'event-date',
                    'compare' => 'EXISTS',
                ),
                array(
                    'key' => 'event-date',
                    'value' => time(),
                    'compare' => '>=',
                    'type' => 'NUMERIC',
                ),
            );
    
     $query->set( 'meta_query', $meta_query );
    
            $query->set( 'meta_key', 'event-date' );        
            $query->set( 'orderby', 'event-date' ); 
    Plugin Author Guido

    (@guido07111975)

    Hi,

    The event-date value (timestamp) is stored as UTC+0 so if you’re in another time zone and compare this with time() it will not match exactly. Depending on the time zone 1 or multiple hours.

    Guido

    Plugin Author Guido

    (@guido07111975)

    Please ignore my previous reply. Function time() is the UTC+0 time. I thought time zone was taken into account, but it’s not.

    Guido

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to display past event details’ is closed to new replies.