Trying to get "next upcoming event" but it's pulling wrong event…

Home Forums Calendar Products Events Calendar PRO Trying to get "next upcoming event" but it's pulling wrong event…

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #13653
    Trevor
    Member

    I have a section on my site where I’m trying to pull just the next upcoming event, but it’s like it’s skipping a bunch of events and pulling one from March.

    You can see it here on the main page: http://harvestpensacola.com right where it says “CALENDAR”. And then on the events page, there are obviously other events that it’s not pulling. http://www.harvestpensacola.com/events/

    Here is code: http://pastebin.com/2HmVkTum

    #13706
    Trevor
    Member

    Anyone?

    #13875
    Trevor
    Member

    Any news yet? I really need to get this fixed quickly.

    #13881
    Rob
    Member

    Hey Trevor. Should have a response for you today. Apologies for the delay thus far, we generally don’t get on the forums over the weekends.

    #13909
    Trevor
    Member

    This guys seems to have a similar issue: http://wordpress.org/support/topic/plugin-the-events-calendar-the-next-three-events-in-the-widget?replies=3

    Could it be that there’s no sort by for the tribe_get_events() function that I’m using?

    #13918
    Jonah
    Participant

    Hi Trevor, the code you posted works fine for me. It’s pulling in my closest upcoming event on my local test site even when I have plenty of events after it.

    I wonder if there’s some conflict with another plugin going or some script in your theme? Have you tried disabling some plugins to see if this fixes it? The site you posted loads very slow for me in Chrome so I wonder if this is related to the issue.

    Another thing you could try is to just use WP_Query() and pass in tribe_events as the post type…

    I hope that helps,
    Jonah

    #13922
    Trevor
    Member

    Hi Jonah,

    Okay I will try using get_posts() to pull in the posts… how do I set the date to be after a certain date (or upcoming)?

    #13925
    Trevor
    Member

    Okay Jonah, it’s definitely not a conflict… it’s something with the fact that the next event is a recurring event. It pulls the next events just fine if it’s just a regular, one-off event, but if it is a recurring event, it pulls the event, but the DATE is incorrect…

    See here: http://www.harvestpensacola.com/
    The event is listed as “Growth Track 401 – Dec 23”.

    When if you look here: http://www.harvestpensacola.com/events/upcoming/
    The event is correct, but the date should be Jan 29.

    It’s like it’s pulling the wrong occurrance of the recurring event.

    #13930
    Trevor
    Member

    Okay, I fixed it. In case others run into the same issue, I’ll post the solution.

    Basically, recurring event occurrences have the same post ID, so if you pass an ID into functions like tribe_get_start_date() outside of the loop, you’ll get an unexpected result.

    It works now if I set global $post, and then wp_reset_query() afterward, like so:
    http://pastebin.com/BsYkidsS

    Not sure if this is expected behavior, but it works now.

    #13979
    Rob
    Member

    Thanks for the heads up, Trevor – glad to hear you got this figured out. Let me see if Jonah or anyone else on the team has a suggestion re: how we can workaround the post ID issue in the official code. That way if a fix is possible, we can get it in for 2.1 or a subsequent release.

    #14044
    Joey Kudish
    Member

    Hi Trevor,

    I’m a developer on the team here. As best as I can tell the function is working as intended and I don’t believe that what you’re doing is a hack or workaround, that’s how the function is intended to be used. Am I missing something?

    #14101
    Trevor
    Member

    Yes I see that in the example functions you always declare global $post; and use setup_postdata(). I guess I didn’t realize that this was a requirement for the functions to work properly. Maybe make a note in the knowledge base that mentions they must be used with the global $post variable?

    #14113
    Joey Kudish
    Member

    Hey Trevor,

    Thanks for the suggestion, I’ll pass that along to Rob so that he can update the docs.

    Cheers

    #14177
    Rob
    Member

    Thanks guys! Just a heads up that this has been updated per Trevor’s note.

    #975412
    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 15 posts - 1 through 15 (of 15 total)
  • The topic ‘Trying to get "next upcoming event" but it's pulling wrong event…’ is closed to new replies.