Support

Home Forums Event Espresso Premium EE_Event_List_Query issue in latest releases

EE_Event_List_Query issue in latest releases

Posted: July 17, 2017 at 12:34 pm

Viewing 6 reply threads


wmnf

July 17, 2017 at 12:34 pm

We had our live site updated to 4.9.43p over the weekend and began seeing all taxonomy (categories) for an EE_Event_List_Query that has been limited to one category. This was not occurring on our dev site running 4.9.37p and was duplicated after upgrading to 4.9.44p. Is this a bug?


Josh

  • Support Staff

July 17, 2017 at 12:37 pm

EE_Event_List_Query has actually been deprecated. You can use a standard WP_Query instead.


wmnf

July 17, 2017 at 1:05 pm

Okay, is it possible to query by expired events and order by start_date? Would that be possible in the meta query? Doesn’t seem to work:

$atts = array(
‘post_type’ => ‘espresso_events’,
‘posts_per_page’ => 4,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘espresso_event_categories’,
‘field’ => ‘slug’,
‘terms’ => ‘wmnf-events’
)
),
‘orderby’ => ‘start_date’,
‘sort’ => ‘ASC’
);


Josh

  • Support Staff

July 17, 2017 at 1:59 pm

It is possible but instead of using params in the method call, you use the post_fields, post_join, and post_where filters.

There’s some example code here:

https://gist.github.com/joshfeck/103efd299ce615188e978293a1254eeb


wmnf

July 17, 2017 at 4:05 pm

So, how can I init that example code with WP_Query? I’ve tried adding a filter for pre_get_posts using the template function in your example along with all the example code added to our functions file, but nothing is listed as a result…

add_filter( 'pre_get_posts', 'wmnf_ee_event_list_query_template_function' );
function wmnf_ee_event_list_query_template_function( $query ) {
    if ( ( $query->is_main_query() ) && ( 'espresso_events' == get_post_type() ) ){
        //$query->set( 'posts_per_page', 10 ); // or other value
        add_filter( 'posts_fields', 'wmnf_ee_posts_fields' );
        add_filter( 'posts_join', 'wmnf_ee_posts_join' );
        add_filter( 'posts_where', 'wmnf_ee_posts_where' );
        add_filter( 'posts_orderby', 'wmnf_ee_posts_orderby' );
    }
}
function wmnf_ee_posts_fields( $sql ) {
    $sql .= ', ' . EEM_Datetime::instance()->table() . '.* ' ;
    $sql .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ' ;
    return $sql;
}
function wmnf_ee_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 wmnf_ee_posts_where( $sql ) {
    $sql .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > "' . current_time( 'mysql', true ) . '" ';
    return $sql;
}
function wmnf_ee_posts_orderby( $sql ) {
    $sql = ' event_start_date ASC ';
    return $sql;
}


Josh

  • Support Staff

July 18, 2017 at 7:27 am

Can you check to see if your custom query is the main query?


wmnf

July 18, 2017 at 7:51 am

No, it was not the main query and why not working. This is a listing of next four upcoming events on our home page and the main query pertains to a featured post. I ended up creating a view with all info and using get_results.

Viewing 6 reply threads

The support post ‘EE_Event_List_Query issue in latest releases’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso