[Resolved] Custom Event Taxonomy Archive

Home Forums Support [Resolved] Custom Event Taxonomy Archive

Home Forums Support Custom Event Taxonomy Archive

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #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.

    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.4
    GP Premium 1.7.2
    #670416
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Just so I understand, are you wanting your event_types archive to look like your events/list page?

    I think you were on the right track with pre_get_posts, but it looks like the event_types is using Elementor, so I’m not sure if that’s possible with them?

    #670430
    Heidi

    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!

    #670782
    Tom
    Lead Developer
    Lead Developer

    Hi 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 ๐Ÿ™‚

    #674928
    Heidi

    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!

    #675569
    Tom
    Lead Developer
    Lead Developer

    Perfect! Thanks for sharing your code ๐Ÿ™‚

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