Support

Home Forums Event Espresso Premium Sort EEH_Event_Query by event name

Sort EEH_Event_Query by event name

Posted: June 1, 2017 at 8:45 am

Viewing 3 reply threads


10amcreative

June 1, 2017 at 8:45 am

I’m using EE4 and I’d like to sort my query by name.

I have a custom query using your recommended code to attach to the $wp_query call: $wp_query = new EE_Event_List_Query( $atts ); and everything is working fine except that I can’t sort by name.

The 'order_by' -> in $atts defaults to ORDER BY event_start_date in the query.

I found the function in the core file that parses the ‘order_by’ field here: https://github.com/eventespresso/event-espresso-core/blob/a03b30cbc127991fe11b30e3b20fcfe9d01fea15/core/helpers/EEH_Event_Query.helper.php#L257

Unfortunately, I see that the only sorting options are ticket and venue related.

Is there a way to add another ‘case’ to this function to sort by event name without modifying a core file? Or maybe there’s another approach to sort this query by name that I haven’t considered.


Josh

  • Support Staff

June 1, 2017 at 1:50 pm

Hi there,

EE_Event_List_Query was actually deprecated. A few options you can consider would be to use the EventListQuery class with your own attributes, or you can use the WP_Query without the extended class.

If you can post some example code in a gist or pastebin I can give you more specific examples on what to change there.


10amcreative

June 2, 2017 at 12:12 pm

Thanks Josh!

Here’s a link to the code: https://pastebin.com/nZpFvKLu

Let me know what you recommend.


Josh

  • Support Staff

June 6, 2017 at 12:03 pm

Here’s one idea that uses WP_Query instead:

https://gist.github.com/joshfeck/ae206b13b751743b08137e72dc55151e

Viewing 3 reply threads

The support post ‘Sort EEH_Event_Query by event name’ 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