wp-admin->Events set default sort by date

Home Forums Calendar Products Events Calendar PRO wp-admin->Events set default sort by date

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1297562
    Ching-Chih
    Participant

    Hello!

    So when I view my Events in the wp-admin page, it’s always sorted in some random way. Is there some way that I can have it sort by the date of the event by default?

    Thank you!

    #1297965
    Courtney
    Member

    Hello

    I believe the events are sorted by the end dates, with the furthest in the future displaying first.

    You can check out Advanced Post Manager https://wordpress.org/plugins/advanced-post-manager/ that offers additional sorting options on your Events in the dashboard.

    Let me know if this resolves the issue for you.

    Thanks
    Courtney πŸ™‚

    #1298144
    Ching-Chih
    Participant

    Hey Courtney,

    Thanks for the pointer. That gives me the option to add different sorting options, but my goal is that when I or a user views the admin view of the Events list, that it sorts by the start-date, ascending by default.

    Right now it sorts by start-date, descending and I have to manually click on the date to sort it ascending.

    Any pointers to code in WP or The Event Calendar to change this default behavior would be great!

    #1298780
    Courtney
    Member

    Hello

    Add this snippet to either your child theme’s functions.php file or use the My Custom Functions plugin.

    add_filter( 'posts_clauses', function( $pass, $query ) {
        $screen = get_current_screen();
    
        if (
            ! $screen
            || Tribe__Main::instance()->doing_ajax()
            || 'edit' !== $screen->base
            || 'tribe_events' !== $screen->post_type
        ) {
            return;
        }
    
        $query->set( 'order', 'ASC' );
        return $pass;
    }, 10, 2 );

    Let me know if that works for you.

    Thanks
    Courtney πŸ™‚

    #1298978
    Ching-Chih
    Participant

    Excellent, that’s exactly what I needed!

    #1298983
    Ching-Chih
    Participant

    Actually I stand corrected, the admin view does sort correctly, but now when I view my WP site, I get an “undefined function get_current_screen()”

    However if I wrap my code in:

    if (is_admin()) { … }

    Then everything works. Thanks again!

    • This reply was modified 6 years, 10 months ago by Ching-Chih.
    • This reply was modified 6 years, 10 months ago by Ching-Chih.
    #1298995
    Ching-Chih
    Participant

    Found out that it his the customize preview too, so:

    Wrapped in:

    if (is_admin() && !is_customize_preview()) { … }

    #1299038
    Courtney
    Member

    Thanks again! Glad it looks as you’d like now πŸ™‚

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘wp-admin->Events set default sort by date’ is closed to new replies.