Home › Forums › Pro Support › Sorting Events Calendar Events by Event Start Date instead of Publish Date?
Tagged: Events Calendar, Start Date
- This topic has 7 replies, 4 voices, and was last updated 3 years ago by
elvin.
-
AuthorPosts
-
April 6, 2020 at 11:12 am #14502
Bodie J
ParticipantI am using WP Show Posts to gloriously display Events Calendar Posts all over my website. I have a “This Week” Section on our homepage where I have an Events Calendar Shortcode showing this week’s events and below it, I have a WPSP shortcode doing the same but mostly just the featured images. My goal is to get the events to sort chronologically based on when they actually occur, not based on when the post I created them.
I have the code below forcing my Events Calendar Admin to always sort the events chronologically with the next event to occur on the top of the list. Is there a way I can match this sorting using WPSP on my homepage?
/* Sort Events by Ascending as a Default */ function order_events_by_next_start_date( $wp_query ) { if (is_admin()) { $post_type = $wp_query->query['post_type']; if ( $post_type == 'tribe_events') { $wp_query->set('orderby', 'start_date'); $wp_query->set('order', 'ASC'); } } } add_filter('pre_get_posts', 'order_events_by_next_start_date');
The
start_date
is the date that I would like to have WPSP sort by, and then sort ascending.Is this possible? You can see how it is now at the link below:
Thanks
Bodie
April 6, 2020 at 6:06 pm #14516Tom
KeymasterHi there,
You should be able to add that to the shortcode.
Something like this:
[wp_show_posts id="123" settings="orderby=start_date&order=ASC"]
Let me know 🙂
April 6, 2020 at 9:24 pm #14520Bodie J
ParticipantTom,
Thanks for the reply, but for some reason it doesn’t seem to work. Is there any particular settings I should set in the “More Settings” section?
I am trying to go for the same effect on both of these pages.
https://hcf.cc/#this-week
https://hcf.cc/services/I simply want to organize them chronologically with the next one coming up be the first one in the list. Your shortcode adjustment should work but it doesn’t seem to? I wrote the date in the title so it is easier to see what day they occur on. For whatever reason, they don’t seem to be ordering by
start_date
.What else should I try?
Appreciate your help, as always.
Bodie
April 7, 2020 at 8:00 pm #14548Tom
KeymasterWeird, let’s debug to see if the parameters are making it through:
add_filter( 'wp_show_posts_shortcode_args', function( $args ) { var_dump($args); return $args; } );
What does that output above your list?
April 7, 2020 at 9:58 pm #14550Bodie J
ParticipantOk here we go:
This was above the “THIS WEEK” Section on the homepage: https://hcf.cc/#this-week
array(6) { ["order"]=> string(3) "asc" ["orderby"]=> string(10) "start_date" ["post_type"]=> string(12) "tribe_events" ["posts_per_page"]=> int(8) ["post_status"]=> array(1) { [0]=> string(7) "publish" } ["tax_query"]=> array(1) { [0]=> array(4) { ["taxonomy"]=> string(8) "post_tag" ["field"]=> string(4) "slug" ["terms"]=> array(1) { [0]=> string(9) "this-week" } ["operator"]=> string(2) "IN" } } }
and this was on the Online Services Page: https://hcf.cc/services/
array(7) { ["order"]=> string(3) "asc" ["orderby"]=> string(10) "start_date" ["post_type"]=> string(12) "tribe_events" ["posts_per_page"]=> int(10) ["paged"]=> int(0) ["post_status"]=> array(1) { [0]=> string(7) "publish" } ["tax_query"]=> array(1) { [0]=> array(4) { ["taxonomy"]=> string(8) "post_tag" ["field"]=> string(4) "slug" ["terms"]=> array(1) { [0]=> string(15) "online-services" } ["operator"]=> string(2) "IN" } } }
I left them on the page for now if you want to see.
Thanks
April 8, 2020 at 7:35 pm #14586Tom
KeymasterCan you try
ASC
instead ofasc
?Everything else looks good to me.
September 21, 2020 at 2:49 am #19675Gary
ParticipantI am having the same problem. My events will not sort by ‘Upcoming’ order.
I have debugged and get the following:
array(5) { ["order"]=> string(4) "desc" ["orderby"]=> string(15) "event_dates_asc" ["post_type"]=> string(8) "gd_event" ["posts_per_page"]=> int(10) ["post_status"]=> array(1) { [0]=> string(7) "publish" } }
I am using this shortcode:
[wp_show_posts id="14475" settings="orderby=event_dates_asc" ]
The event_dates_asc is custom meta from Geodirectory.
September 21, 2020 at 1:46 pm #19711elvin
ModeratorHi Gary,
Can you start a new topic and provide the details on it? Thanks. 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.