Support

Home Forums Event Espresso Premium Query event with multiple categories

Query event with multiple categories

Posted: December 20, 2018 at 9:09 am

Viewing 2 reply threads


ARAGATO

December 20, 2018 at 9:09 am

Lets say we have:
Event1: categories: Public, Cinema
Event2: categories: Private, Cinema
Event2: categories: Public, Theater

When querying for events using only one category it is pretty straight forward:

EEM_Event::instance()->get_all(array('order_by' => 'Datetime.DTT_EVT_start', 'order' => 'ASC',array('Term_Taxonomy.taxonomy' => 'espresso_event_categories','Term_Taxonomy.Term.slug' => 'cinema') ) );

That returns events 1 and 2. However, when I want only events that have both categoryies Cinema and Private, I am stuck. Something like this does not work.

EEM_Event::instance()->get_all(array('order_by' => 'Datetime.DTT_EVT_start', 'order' => 'ASC',array('Term_Taxonomy.taxonomy' => 'espresso_event_categories','Term_Taxonomy.Term.slug' => 'cinema', 'Term_Taxonomy.Term.slug*' => 'private') ) );

What’s missing, how to select events with having at least two or more of a provided array of categories?


Josh

  • Support Staff

December 21, 2018 at 3:08 pm

The model system doesn’t currently support this in one query. What you could do instead is run a regular wp query like this:

$query = [ 'tax_query' => [ [ 'taxonomy' => 'espresso_event_categories', 'terms' => array( 12, 13 ), 'operator' => 'AND' ] ], 'post_type' => 'espresso_events' ];

$posts = get_posts( $query );


ARAGATO

December 22, 2018 at 6:01 am

Nice, Josh.
I just had to a fields parameter for the tax_query so I could select from slug instead of id.
Resolved.

Viewing 2 reply threads

The support post ‘Query event with multiple categories’ 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