0

How can I modify the following call so upcoming events show up first. Currently the order is very random; I need to show most current events at the top and any past events should not be showing...

    <div class="events-links">

    <?
    include "eventbrite/Eventbrite.php"; 
    $authentication_tokens = array('app_key'  => 'APP_KEY',
                       'user_key' => 'USER_KEY');
    $eb_client = new Eventbrite( $authentication_tokens );
    $events = $eb_client->user_list_events();
    ?>

    <span class="inspirational">Upcoming Events</span>
    <?= Eventbrite::eventList( $events, 'eventListRow'); ?>
    </div>
  • these are not my tokens; I changed them prior to posting to just random characters :)
000
  • 26,951
  • 10
  • 71
  • 101
Alex
  • 31
  • 4

2 Answers2

2

If you're using the user_list_events method, you can filter your results by adjusting the event_statuses field. Valid options include: live, started, or ended. To display only upcoming events, for example: event_statuses=live.

The results will display from soonest upcoming event to event happening farthest in the future.

Claire
  • 169
  • 4
  • thank you - where do I adjust this field (in the code I have) – Alex Mar 27 '13 at 16:27
  • You can look in the `examples` directory for the PHP client: https://github.com/ryanjarvinen/eventbrite.php/blob/master/examples/attendee-list-example.php – brianz Mar 27 '13 at 18:11
  • This example in here is the exact code that I pasted up above in my question..... – Alex Apr 02 '13 at 23:48
1

After you fetch $events, use usort to sort the array.

usort: http://php.net/manual/en/function.usort.php

$events = $eb_client->user_list_events();
usort($events, function($a, $b) {
    $adate = $a->start // or $a['date'] or $a->whatever it is
    $bdate = $b->start // or $a['date'] or $a->whatever it is
    if ($adate < $bdate) return -1;
    if ($adate > $bdate) return 1;
    return 0;
});

Alternatively, you can contact your account manager if you have one.

(Disclosure: I work for an EB competitor)

000
  • 26,951
  • 10
  • 71
  • 101
  • This code puts out an error, I have error logging turned off though – Alex Mar 27 '13 at 15:57
  • Not sure how to utilize this then; my experience is in front-end development (html/css/jquery/design); I am not sure how I can deploy the usort function – Alex Mar 27 '13 at 17:03
  • What does var_dump($events) look like? – 000 Mar 27 '13 at 17:10
  • It spits out the full event as listed on eventbrite.com for each event; it's too much content and too many parameters to neatly paste on here... – Alex Apr 02 '13 at 23:51