Home › Forums › Calendar Products › Events Calendar PRO › tribe_get_events orderby Post Date rather than Event Start Date
- This topic has 5 replies, 3 voices, and was last updated 10 years, 2 months ago by
Support Droid.
-
AuthorPosts
-
November 5, 2015 at 3:44 pm #1022372
joeleadedesign
ParticipantHi 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:
- https://wordpress.org/support/topic/possible-fix-for-tribe_get_events-ignores-values-of-order-and-orderby-args?replies=13#post-4814011
- https://theeventscalendar.com/support/forums/topic/tribe_get_events-sort-order/
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
November 6, 2015 at 12:21 pm #1022655Geoff
MemberHey 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!
GeoffNovember 8, 2015 at 3:44 pm #1023082joeleadedesign
ParticipantThanks Geoff. I’ve tried using WP_Query with
post_type=tribe-eventsbut it hasn’t helped. It’s still returning the posts in descending order by_EventStartDaterather than thepost_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 apost_dateof 09-Nov-2015 and an_EventStartDateof 25-Nov-2015.
Event B has apost_dateof 05-Nov-2015 and an_EventStartDateof 28-Nov-2015.
Event B is showing for my query but Event A should be appearing because thepost_dateis the highest/farthest into the future.TEST 2
——
Event A has an updatedpost_dateof 03-Nov-2015 and an_EventStartDateof 25-Nov-2015.
Event B has apost_dateof 05-Nov-2015 and I’ve changed the_EventStartDateto 21-Nov-2015.
Event A is showing for my query but Event B should be appearing because thepost_dateis 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
November 8, 2015 at 3:45 pm #1023083joeleadedesign
ParticipantHa ha. That was a poor use of the code tag, sorry 🙂
November 10, 2015 at 6:51 am #1023692Geoff
MemberHi 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
February 18, 2016 at 8:30 am #1075513Support Droid
KeymasterThis 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. -
AuthorPosts
- The topic ‘tribe_get_events orderby Post Date rather than Event Start Date’ is closed to new replies.
