Support

Home Forums Event Espresso Premium EE4: Is there a way to use the number of upcoming events as orderby in args

EE4: Is there a way to use the number of upcoming events as orderby in args

Posted: May 16, 2017 at 9:50 am


10amcreative

May 16, 2017 at 9:50 am

I’m getting terms from the espresso_event_category taxonomy and I’d like to set the order to be based on the number of upcoming events. Currently, I have this code, which orders by the total list of events:


$taxonomy = array('espresso_event_categories');
$args = array('orderby'=>'count','order'=>'DESC','hide_empty'=>true);
$ee_terms = get_terms($taxonomy, $args);

Of course the ‘orderby’=>’count’ includes expired events and I’m just looking for a count of the upcoming events to order by.

Is there a way to do this?


Josh

  • Support Staff

May 16, 2017 at 11:04 am

Hi there,

You can use the where clause to filter out any events that have ended.

e.g.
$where_params = EEM_Datetime::instance()->table() . ".DTT_EVT_end > '" . current_time( 'mysql', true );
‘where’ => $where_params;`


10amcreative

May 16, 2017 at 1:24 pm

Thanks for the quick reply Josh!

Unfortunately it’s not working for me yet. Here’s my updated code with the where clause in the args:

$taxonomy = array('espresso_event_categories');
$where_params = EEM_Datetime::instance()->table() . ".DTT_EVT_end > '" . current_time( 'mysql', true );
$args = array('orderby'=>'count','order'=>'DESC','where'=>$where_params,'hide_empty'=>true);
$ee_terms = get_terms($taxonomy, $args);

Thanks again for your help with this!


Josh

  • Support Staff

May 16, 2017 at 1:36 pm

The $where_params I shared with you actually should go with a query for events, then from there you can get the count and use that number for your taxonomy query.


10amcreative

May 17, 2017 at 8:20 am

Yup, that got it working. Thanks Josh!

The support post ‘EE4: Is there a way to use the number of upcoming events as orderby in args’ 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