tribe_get_events orderby Post Date rather than Event Start Date

Home Forums Calendar Products Events Calendar PRO tribe_get_events orderby Post Date rather than Event Start Date

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1022372
    joeleadedesign
    Participant

    Hi Guys,

    I have a section on the home page on my local install of eamba.amba.org.au that pulls in a single event using tribe_get_events(). I’m trying to grab the post that was most recently created (post_date). My arguments are currently:

    $events = tribe_get_events( array(
    'posts_per_page' => 1,
    'orderby'        => 'date',
    'order'          => 'DESC',
    ) ); ?>

    This query, however, returns the event with the event start date that is farthest in the future. I’ve tried orderby => ID rather than date, as this is effectively the same thing (assuming one doesn’t change the post_date manually) but I can’t seem to make it work as intended.

    Here are the forum posts I’ve read and applied to resolve it but without any success:

    Any help would be appreciated. BTW, our license is a free community one (we’re a not-for-profit), so if this precludes me from support I understand.

    I’ve ticked the “YES, I’ve reverted to TwentyFourteen…” box and “YES, I’ve deactivated…” checkboxes in order to send this request. I have to use the theme, Forsythes, in order to use the query, and have those plugins enabled to make the page work.

    Thanks,

    Joel

    #1022655
    Geoff
    Member

    Hey Joel,

    Thanks for reaching out! Also, thanks for being up front about the free license and the fact that this is a support question for a non-profit.

    I’m happy to help as best I can, or at least point you in the right direction. In this case, I would suggest using a custom query with WP_Query instead. Here’s an example of how to query a custom post type–which is tribe-events for The Events Calendar. From there, you could use the order and orderby parameters to target the post date to show in descending order.

    Will that help you get started? Nice work using tribe_get_events — it just might not be flexible enough to do exactly what you’d like. 🙂

    Cheers!
    Geoff

    #1023082
    joeleadedesign
    Participant

    Thanks Geoff. I’ve tried using WP_Query with post_type=tribe-events but it hasn’t helped. It’s still returning the posts in descending order by _EventStartDate rather than the post_date.

    Here’s are my test use cases. The query is saved to CodePen – http://codepen.io/JoelEadeDesign/pen/KdGeWb. (FYI: I’m writing the date as Day-Month-Year to avoid any confusion, seeing as I’m in Australia and use a different date format than the US).

    TEST 1
    ——
    Event A has a post_date of 09-Nov-2015 and an _EventStartDate of 25-Nov-2015.
    Event B has a post_date of 05-Nov-2015 and an _EventStartDate of 28-Nov-2015.
    Event B is showing for my query but Event A should be appearing because the post_date is the highest/farthest into the future.

    TEST 2
    ——
    Event A has an updated post_date of 03-Nov-2015 and an _EventStartDate of 25-Nov-2015.
    Event B has a post_date of 05-Nov-2015 and I’ve changed the _EventStartDate to 21-Nov-2015.
    Event A is showing for my query but Event B should be appearing because the post_date is now the highest/farthest into the future.

    Here’s the query returned when I vardump it to the page:
    string(833) "SELECT SQL_CALC_FOUND_ROWS DISTINCT fsyth_posts.*, MIN(fsyth_postmeta.meta_value) as EventStartDate, MIN(tribe_event_end_date.meta_value) as EventEndDate FROM fsyth_posts INNER JOIN fsyth_postmeta ON ( fsyth_posts.ID = fsyth_postmeta.post_id ) LEFT JOIN fsyth_postmeta as tribe_event_end_date ON ( fsyth_posts.ID = tribe_event_end_date.post_id AND tribe_event_end_date.meta_key = '_EventEndDate' ) WHERE 1=1 AND ( fsyth_postmeta.meta_key = '_EventStartDate' ) AND fsyth_posts.post_type = 'tribe_events' AND (fsyth_posts.post_status = 'publish' OR fsyth_posts.post_status = 'acf-disabled') AND (fsyth_postmeta.meta_value >= '2015-11-09 10:42:03' OR (fsyth_postmeta.meta_value <= '2015-11-09 10:42:03' AND tribe_event_end_date.meta_value >= '2015-11-09 10:42:03' )) GROUP BY fsyth_posts.ID ORDER BY EventStartDate DESC LIMIT 0, 1". That’s all a bit over my head…

    Let me know if you want me to do a video screencast or anything else that may help out.

    Cheers,

    Joel

    #1023083
    joeleadedesign
    Participant

    Ha ha. That was a poor use of the code tag, sorry 🙂

    #1023692
    Geoff
    Member

    Hi Joel,

    Thanks for the extra info! I wonder if you could use a normal post query and filter it with a snippet instead. For example:

    https://gist.github.com/geoffgraham/b3e17ea1bb2a6464b119

    You can change the conditions and the variables, but the general idea is the same: filter the query from functions.php rather than the template itself.

    Let’s give that a try instead and see if it helps. 🙂

    Geoff

    #1075513
    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 6 posts - 1 through 6 (of 6 total)
  • The topic ‘tribe_get_events orderby Post Date rather than Event Start Date’ is closed to new replies.