• Resolved nukurt

    (@kurtnuimage)


    Hi,

    So, I’m using the Events Calendar and I’d like to add a custom order to my events.

    ‘The client doesn’t want them ordered by date, but instead would like to use a “menu_order” param. This is because they have 4 events they want displayed in a set order.

    So I’ve added the “menu_order” page attribute to the tribe_event post type without issue by using the ‘register_post_type_args’ filter. But when it comes to displaying the events in this order I’m having a lot of difficulty.

    I’ve tried using both ‘pre_get_posts’ & ‘tribe_events_archive_get_args’ filters, but neither seem to change the ordering at all.

    Weirdly if i use the pre_get_posts filter, if i add some debugging to the get_view_html() function (to show var_dump($query->posts)); They actually appear to be in the correct order, but by the time the template file is loaded they have changed back to date order.

    The only view i need to display is the list view ([your-theme]/tribe/events/v2/list.php), all other views have been removed from displaying.

    Can you please help me out, it shouldn’t be so difficult to change some of the query args passed into the template file.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Darian

    (@d0153)

    Hi @kurtnuimage

    Thanks for getting in touch, I would be happy to point you in the right direction.

    Your desired use-case scenario may be possible with some custom coding, but if you decide to give that a try, please note we cannot provide full support for custom implementations like that.

    A good place to start would be our Themer’s Guide, if you’re comfortable doing it DIY. https://theeventscalendar.com/knowledgebase/guide/customization/

    In the meantime, I will inquire with the team to determine whether the order can be modified easily. I will provide you with an update as soon as I gather more information.

    Plugin Support Darian

    (@d0153)

    Hi there,

    It seems like it has been some time since we received a response from you, therefore, I will consider this matter as resolved. If you require any further assistance, please do not hesitate to start a new thread.

    Plugin Support Darian

    (@d0153)

    Hi @kurtnuimage

    One my colleagues just provided a code snippet for this:

    / Change to show events based on menu_order
    add_filter( 'tribe_events_views_v2_view_list_template_vars', 'tec_events_by_menu_order', 100 );

    function tec_events_by_menu_order( $template_vars ) {

    // Sort the array using usort and the comparison function
    usort(
    $template_vars['events'],
    function ( $a, $b ) {
    if ( $a->menu_order == $b->menu_order ) {
    return 0;
    }

    return ( $a->menu_order < $b->menu_order ) ? - 1 : 1;
    }
    );

    return $template_vars;
    }

    Note that this only works well if all events are shown on one page in the list view.
    So, the “Number of events to show per page” must be higher than the actual number of events.

    As always, please test this first on a staging site before applying to your live site. This is to avoid unnecessary downtime to your live site.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.