So recently I’ve upgraded a client’s WordPress install 4.8 and their Event Expresso plugin to 4.9.42.p, both are the latest version of their respective codebases as of June 18, 2017. When I upgraded, I receive the following error:
Fatal error: Class 'EE_Event_List_Query' not found in /home/my-account/public_html/my-website/wp-content/themes/my-theme/index.php on line 71
Based on some initial research, I should not be getting this issue. On Event Expresso’s change log, I see that this error was fixed on June 8, 2017 with patch 4.9.40p.
https://eventespresso.com/wiki/ee4-changelog/
Further investigation a simular issue leads me to the actual line of code in the core that was patched. https://github.com/eventespresso/event-espresso-core/issues/232
Upon more research, I see that the function has been deprecated per this links: https://eventespresso.com/topic/ee_event_list_query-not-working/
In the forum, a solution was offered which is to change the line of code from something like this…
$wp_query = new EE_Event_List_Query( $atts );
…to something like this:
$wp_query = new EventEspresso\core\my-website\services\wp_queries\EventListQuery( $atts );
Based on experience mixed with a little gut-instinct, this solution here seems a little hackey / unstable. I mean, what if my domain or filesystem changes. This would have to change as well. Luckly, in another forum a solution was offered along the lines of using the built in WP_Query. This one is a bit more involved, but it feels more long term than the previous solution. There’s a couple parts to this solution. It’s a bit more involved, but it probably is the best long term play. Part 1 is to add the custom filter functions. In the example, they put it at the top. I threw this into functions.php since I’m using this in a few areas.
function my_posts_join ( $sql ) {
$sql .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() . '.ID = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name() . ' ) ';
return $sql;
}
function my_posts_where ( $sql ) {
$sql .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end >= "' . current_time( 'mysql', true );
return $sql;
}
function my_posts_orderby ( $sql ) {
$sql .= '" order by '. EEM_Datetime::instance()->table() . '.DTT_EVT_end desc';
return $sql;
}
And then I had to add the filter, set my arguments, and then execute the WP_Query
global $wp_query;
add_filter( 'posts_join', 'my_posts_join' );
add_filter( 'posts_where', 'my_posts_where' );
add_filter( 'posts_orderby', 'my_posts_orderby' );
$args = array( 'post_type' => 'espresso_events', 'post_status' => 'publish', 'show_expired' => FALSE, 'posts_per_page' => 3, );
$wp_query = new WP_Query( $args );
And that’s basically it, I can then check to see if there’s any post of the Event Expresso type and if there is, loop through all of them and do what I need to do, which in the case is to show a listing of upcoming events.
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) :
$wp_query->the_post();
$check = $post->EE_Event->is_upcoming();
...
endwhile;
endif;
Whew! Another crisis averted!