Support

Home Forums Event Espresso Premium Reorder events within a category archive (menu_order)

Reorder events within a category archive (menu_order)

Posted: January 5, 2017 at 4:57 am

Viewing 7 reply threads


KineticPulse

January 5, 2017 at 4:57 am

My client wants to be able to manually order events within a category archive page. With regular custom posts I would do this by changing the loop query to ‘orderby’=>’menu_order’ and get them to amend the ‘sort order’ in the post or use a post re-ordering plugin. However, this doesn’t seem to be possible with Events – any plugin I use for drag & drop reordering doesn’t work for Events.

Can you suggest a way of allowing manual reordering of events?


Josh

  • Support Staff

January 6, 2017 at 9:14 am

Hi there,

Yes, there’s a hook that you can use to add support for the Menu Order option in the Page Attributes box of the Event Espresso event editor:

https://gist.github.com/joshfeck/982b124869afadd38f3ce19dedf8721a

You can add the above to a functions plugin or into your WordPress theme’s functions.php file.


KineticPulse

January 6, 2017 at 9:52 am

Unfortunately it seems to make no difference..

My code is


global $wp_query;
$args = array_merge( $wp_query->query_vars, array( 'orderby'=>'menu_order','order'=>'ASC' ) );
query_posts( $args );

But the page is still listing posts in post_date order


Josh

  • Support Staff

January 6, 2017 at 9:58 am

It will help to see that code in context, can you post that in a gist or paste bin?

Along with that, I should mention that the code in the gist only adds support for changing the menu order values within the event, so did you make sure the event posts have menu_order values set?


KineticPulse

January 6, 2017 at 10:02 am

Sure – I’ve manually added sort order to some events to test, and the code is on the taxonomy-espresso_event_categories.php template

https://gist.github.com/bathdrummer/5c956aecb80bf6aaa15351944d9235d4


Josh

  • Support Staff

January 6, 2017 at 10:02 am

Oh and for what it’s worth, it’s recommended to use get_posts() instead of query_posts().

https://developer.wordpress.com/2012/05/14/querying-posts-without-query_posts/


Josh

  • Support Staff

January 6, 2017 at 12:00 pm

OK thanks, so you can remove the call to query_posts() from the template, and the add a filter function to a functions file that hooks into the
pre_get_posts hook that will set the orderby for category archives.

https://gist.github.com/joshfeck/982b124869afadd38f3ce19dedf8721a#file-set_tax_query_orderby-php


KineticPulse

January 6, 2017 at 3:24 pm

Brilliant, works perfectly. Thanks!

Viewing 7 reply threads

The support post ‘Reorder events within a category archive (menu_order)’ 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