- This topic has 5 replies, 2 voices, and was last updated 3 years, 8 months ago by
Tom.
-
AuthorPosts
-
September 5, 2018 at 9:39 pm #669981
Heidi
Hi again,
I think I’m out of my league, but am making a last-ditch effort to see if I’m anywhere near a solution that matches my skill level.
-
I created a custom taxonomy called “Event Types” for events created in The Events Calendar.
-
I use that “Event Types” taxonomy in a right sidebar drop-down menu so users can sort by Event Type from single event pages. Example > https://nusciencesolutions.com/event/healthy-meal-preparation-for-cancer-cold-soups/
-
The archive page that is returned for the sort comes from the standard archive.php. Example > https://nusciencesolutions.com/event_types/self-care/
This would be fine, except that my client has asked if we can sort by date, from earliest to latest. I’d also like to show the date of each event on the Event Type archive page. Since the Elementor archive widget template doesn’t include Events Calendar dates in the meta data that can be displayed, I’d like the Event Type archive display to mirror that of the Events Calendar List format > https://nusciencesolutions.com/events/list/.
I assume this is possible with php. I tinkered a little, copying the GP archive.php, renaming it taxonomy-event_types.php, placing it in my generatepress_child folder, and playing around with pre_get_posts and other php code I found. Nothing worked.
So here I am to see if the brilliant experts at GP can/will help. Maybe there’s an easier way that I’m missing? Totally cool if you tell me this is beyond your scope. Thanks!
GeneratePress 2.1.4GP Premium 1.7.2September 6, 2018 at 8:56 am #670416Tom
Lead DeveloperLead DeveloperHi there,
Just so I understand, are you wanting your
event_types
archive to look like yourevents/list
page?I think you were on the right track with
pre_get_posts
, but it looks like theevent_types
is using Elementor, so I’m not sure if that’s possible with them?Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentSeptember 6, 2018 at 9:11 am #670430Heidi
Hey Tom,
Yes to your first question (in a perfect world), and I am willing to forego the Elementor archive card skin layout to achieve it.
But if a list view isn’t possible given how I’ve used Elementor to design every other aspect of the site, I will settle for simply being able to display sorted event_types, using the existing Elementor archive card skin layout, in ascending date order (soonest to latest).
If using pre_get_posts can give me the latter, I’ll need to know exactly how to word/structure it and where to place it. Can I simply put it in Code Snippets? Or will I need to put it in a taxonomy-event_types.php file (copied from archives.php) and place in the GP child theme? If the latter, where do I place the pre_get_posts content? Before or in the Loop?
Thanks very much!
September 6, 2018 at 7:58 pm #670782Tom
Lead DeveloperLead DeveloperHi there,
Give this a shot:
add_action( 'pre_get_posts', function( $query ) { if ( ! is_admin() && $query->is_main_query() && is_tax( 'event_types' ) ) { $query->set( 'order', 'ASC' ); } return $query; } );
Let me know ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentSeptember 11, 2018 at 9:13 pm #674928Heidi
Hi Tom,
Sorry for my delayed response. Thanks for pointing me in the right direction, as always! That code did switch the order, but I had to refine further to get exactly what I wanted. Here’s what ultimately worked for me:
add_action( 'pre_get_posts', function( $query ) { if ( ! is_admin() && $query->is_main_query() && is_tax( 'event_types' ) ) { $query->set( 'meta_key', '_EventStartDate' ); $query->set( 'orderby', array( 'meta_value' => 'ASC' )); } return $query; } );
Thanks again. Worth an extra donation for your ongoing stellar support!
September 12, 2018 at 9:16 am #675569Tom
Lead DeveloperLead DeveloperPerfect! Thanks for sharing your code ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.