Support

Home Forums Event Espresso Premium orderby / sort by meta value

orderby / sort by meta value

Posted: August 28, 2014 at 9:14 am

Viewing 3 reply threads


Idlewild

August 28, 2014 at 9:14 am

Hello,

im trying to list some events in a special order.
Im using a short code on a page so far, but with a custom template.
[EVENT_CUSTOM_VIEW template_name="events-iw" order_by=venue_id,event_meta=>"skill",date(start_date)]
This is what im trying to do, but it doesnt work.
I should order by the venue, then by a meta_value, another meta_value, and in the end by the starting date.

I’ve found something like this for a custom query:

$args = array(
'post_type' => 'event',
'meta_key' => 'event_start_date',
'orderby' => 'meta_value',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'event_start_date',
'compare' => 'LIKE',
)
)
);
$query = new WP_Query($args);

But i don’t know what the standard query is and how i can modify it.
Also i don’t see how i can make a hierarchy in the ordering with this custom query.

Thanks for any tips!


Sidney Harrell

August 28, 2014 at 3:07 pm

That code for a custom query is for EE3 if you were using the EE3 custom post type feature, which I’m guessing you are probably not.
The problem that you are probably running into is that this part

venue_id,event_meta=>"skill",date(start_date)

is getting passed verbatim to the SQL query. Unfortunately, the SQL DB cannot sort on the event meta, because it is stored in the DB as a serialized field. The only thing you could do would be to resort the results in PHP after they have been fetched from the DB and before they are displayed. It would be a customization of the Custom Templates, so would require hiring a developer to do it. For small jobs like that, we can do up to a couple hours (yours would probably be an hour) on support tokens. The relevant code is in plugins/espresso-custom-templates/index.php, line 39. We would need to make a copy of that function and customize it.


Idlewild

August 29, 2014 at 1:00 am

Hello,

im using EE3.

So one (ugly) option would be to sort by name and have a system like _1_4_2 this in the naming and cut the prefix away when showing it.

Since categories in EE3 do not have a hierarchy, there is no way to filter in different blocks, right. Like sorting by a group of categories A and then by a group of B?

Thanks!


Dean

September 1, 2014 at 2:08 am

Hi,

That’s pretty much correct. The Custom Templates use the Event List which uses an SQL, so as Sidney said, the custom meta can’t be sorted that way.

Viewing 3 reply threads

The support post ‘orderby / sort by meta value’ 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