Don't show category in list if event has passed

Home Forums Calendar Products Events Calendar PRO Don't show category in list if event has passed

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1504404
    dadra
    Participant

    Hi Folks,

    I’m displaying a list of event categories using this code:


    <?php
    $args = array(
    'taxonomy' => 'tribe_events_cat',
    'title_li' => '',
    'orderby' => 'name',
    'order' => 'ASC'
    );
    wp_list_categories( $args );
    ?>

    This works great, except that it shows categories for events that have passed, even when none of the upcoming events use that category. Is there a way to tweak the code so the category list shows categories only from upcoming events?

    Click on “Browse by Category” on this page…

    https://harriscenter.wpengine.com/events

    …and you’ll see “Snowshoe Hikes” in the list. But none of the upcoming events use that category, only past ones.

    Thanks in advance for your help!

    #1506254
    Cliff
    Member

    Hi.

    You could use our recently-added “auto delete” functionality for past events and then use wp_list_category()’s hide_empty argument.

    Would that setup work for you?

    #1506545
    dadra
    Participant

    Hey Cliff,

    Thanks for the idea, but we don’t want to have to delete past events. Is there some method that can list categories only from current or future events, ignoring past events? Some kind of date checking function that can be combined with wp_list_categories? If there’s a different way to show categories than wp_list_categories, I’d be fine with that too. But I need it to show both parent and child categories. I appreciate your help!

    #1509479
    dadra
    Participant

    Would love to hear any additional thoughts on this. Thanks. 🙂

    #1510585
    Jennifer
    Keymaster

    Hello,

    I’m sorry for the delay here…Cliff is out today, so I wanted to jump in and help you out with this until he gets back.

    I couldn’t find any functions that output a list of categories excluding those that don’t have upcoming events…what you might need to do is loop through the upcoming events, grab the categories, and then output that list. I found another post where a user has done something similar, so you may also want to take a look at that as an example.

    Please note that we are limited in the amount of support that we can provide for customizations, but we will do our best to point you in the right direction 🙂

    #1516048
    dadra
    Participant

    Thanks Jennifer. I tried implementing this using the link you shared, but the list still includes event categories from past events. Not sure where to go from here. Any help you folks can provide would be greatly appreciated.

    #1517077
    Cliff
    Member

    Sorry but we’re unable to provide such a customization. I’ll share my line of thinking, which may help you accomplish this on your own:

    • Use tribe_get_events() to get the IDs of all the upcoming events (or within a specific time period)
    • Get all the Event Categories these posts have, possibly via get_the_terms()
    • Get all the Event Categories via get_terms()
    • Minus those with upcoming events from all of them to get the list of categories to be excluded
    • Use wp_list_categories() and pass the categories that don’t have upcoming events to the “exclude” parameter

    Personally, that sounds like some heavy querying and maybe there’s some wpdb() way to do this a bit more efficiently.

    If you need some coding help, you may want to ask your developer or reference our documentation and list of known customizers.

    #1517316
    dadra
    Participant

    Thanks Cliff. I’ll try to find a developer who can handle this. How about we leave this ticket open for a bit and then I’ll post the solution once I have it? I’m sure it’d be useful for other people to see.

    #1518044
    Cliff
    Member

    Sure thing.

    Please note that threads get Closed automatically after a couple weeks of inactivity. If it does get Closed, please open a new thread, adding your current problem description and also linking back to this thread.

    Thank you!

    #1527670
    dadra
    Participant

    Just a quick note to say that I’ve got someone working on this and should be able to post a solution in the near future.

    #1529952
    Cliff
    Member

    Cool. Thanks for being willing to share.

    #1539524
    dadra
    Participant

    Still working on this. Will post the solution soon.

    #1540382
    Cliff
    Member

    Thanks for checking in.

    #1556322
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Don't show category in list if event has passed’ is closed to new replies.