Home › Forums › Calendar Products › Events Calendar PRO › wp-admin->Events set default sort by date
- This topic has 8 replies, 2 voices, and was last updated 8 years, 10 months ago by
Ching-Chih.
-
AuthorPosts
-
June 13, 2017 at 5:49 pm #1297562
Ching-Chih
ParticipantHello!
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!
June 14, 2017 at 10:24 am #1297965Courtney
MemberHello
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 πJune 14, 2017 at 2:54 pm #1298144Ching-Chih
ParticipantHey 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!
June 15, 2017 at 2:01 pm #1298780Courtney
MemberHello
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 πJune 15, 2017 at 11:58 pm #1298978Ching-Chih
ParticipantExcellent, that’s exactly what I needed!
June 16, 2017 at 12:21 am #1298983Ching-Chih
ParticipantActually 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 8 years, 10 months ago by
Ching-Chih.
-
This reply was modified 8 years, 10 months ago by
Ching-Chih.
June 16, 2017 at 1:59 am #1298995Ching-Chih
ParticipantFound out that it his the customize preview too, so:
Wrapped in:
if (is_admin() && !is_customize_preview()) { … }
June 16, 2017 at 5:55 am #1299038Courtney
MemberThanks again! Glad it looks as you’d like now π
-
This reply was modified 8 years, 10 months ago by
-
AuthorPosts
- The topic ‘wp-admin->Events set default sort by date’ is closed to new replies.
