Help Desk

Default Category for Community Events

  • Posts: 19 Topics: 11
    | Permalink

    Hi there,

    Is there a way to assign a default event category to all community events submitted?

    We don’t want users to be able to select categories so we’ve hidden the taxonomy pickers via CSS. Now we just want to assign all events as “Community Events” in our event categories.

    Thanks!

    Posts: 5041
    | Permalink
    Correct Answer

    Hi Bradley,

    Thanks for reaching out!

    There isn’t an out of the box way to do this, but you can do it with a small customization. First, you can copy the template for that page into your child theme by following these instructions. The template can be found at wp-content/plugins/the-events-calendar-community-events/src/views/community/modules/taxonomy.php. You can then add the following code to the template in your child theme, just above the foreach block on line 42:

    // set default category
    if ( 'tribe_events_cat' === $taxonomy && 0 === get_the_ID() && empty( $value ) ) {
        $value = array(16); // Default category term ID
    }

    You’ll need to replace the ’16’ with the ID for the category you want to set as the default. You can find the category ID by going to Events > Event Categories and clicking on the category – it will appear in the URL (see screenshot).

    Let me know how that works for you!

    Thanks,

    Jennifer

    Posts: 19 Topics: 11
    | Permalink

    This code snippet solved the issue right away. Thanks!

    I placed my custom version (with the code snippet added at line 41) in /wp-content/themes/<mytheme>/tribe-events/community/modules/taxonomy.php

    Thanks for your help!

    ( WordPress v4.8.2, Community Events plugin v.4.5.6 )

    Posts: 5041
    | Permalink

    No problem, I’m glad that worked for you! I’ll go ahead and close out this thread, but please feel free to open a new one if you have any other questions!

    Thanks,

    Jennifer

    | Permalink