Possible fix for tribe_get_events ignores values of 'order' and 'orderby' args!
-
After wasting pretty much 2 hours trying to fix this and looking at other posts I think I may have found the problem to a bug with The Events Calendar plugin version Version: 3.0.3
The problem: when using the function
tribe_get_events
to retrieve events it seems to ignore the values oforderby
andorder
resulting in posts always being retrieved by date in ascending order (earliest first) in my experience.I looked at this post carefully: http://wordpress.org/support/topic/plugin-the-events-calendar-events-list-in-chronological-order?replies=51
and tried every solution to no avail.
Then I noticed something odd in the function named:
posts_orderby
in the file:/lib/tribe-event-query.class.php in The Events Calendar plugin around line 482 (or something close to that).
The function has two parameters
$order_sql
and$query
and, in within the function code two variables:$order
and$orderby
, which, check for properties of$query
like so:if ( $query->tribe_is_event || $query->tribe_is_event_category ) { $order = !empty( $query->order ) ? $query->order : $query->get( 'order' ); $orderby = !empty( $query->orderby ) ? $query->orderby : $query->get( 'orderby' );
So then I decided to do a var_dump of
$query->order
and$query->orderby
and like I expected it return empty (or NULL) for both of them.So then I decided to do a var_dump of
$query
to see if the values I passed fororderby
andorder
through my arguments array to thetribe_get_events
function would appear anywhere and they did, but, not the way the code was checking for them. Rather, they appeared as within an array contained in property namedquery
of the $query variable like so:$query->query['order']
and$query->query['orderby']
and this returned the values I had actually passed.So then I changed the above snippet of code to this:
if ( $query->tribe_is_event || $query->tribe_is_event_category ) { $order = !empty( $query->query['order'] ) ? $query->query['order'] : $query->get( 'order' ); $orderby = !empty( $query->query['orderby'] ) ? $query->query['orderby'] : $query->get( 'orderby' );
and that seems to fix things pretty well.
So what I wonder then, is if that is an official fix to the bug or if I’ve offset something or created another bug with my fix. Anyways, I haven’t come across this same fix anywhere else yet so I’m hoping this is accepted by Modern Tribe.
Let me know what you think.
Regards,
racl101.
- The topic ‘Possible fix for tribe_get_events ignores values of 'order' and 'orderby' args!’ is closed to new replies.