The Events Calendar - Community Events: make a category CHECKED by default
<?php
/**
* From https://gist.github.com/cliffordp/6a7f538e3f65876d0f2191d5bd4771df
*
* The Events Calendar - Community Events: make a category CHECKED by default
* Note: This will also auto-check the specified Event Categories on the Edit form, not just the Add New form
*
*/
add_action( 'tribe_events_community_after_the_categories', 'cliff_tribe_community_events_form_tax_checked' );
function cliff_tribe_community_events_form_tax_checked() {
// YOU MUST CHANGE THE input#... to your category's category ID...
// We use .find() instead of all in one jQuery() so that we can easily check multiple boxes if we want to--just duplicate the line with .find() in it and change that category ID (like the commented out line)
?>
<script>
jQuery( document ).ready( function() {
const ce_event_cats = jQuery( "#tribe-community-events #event-categories" );
// Event Category ID 8 is checked by default
jQuery( ce_event_cats ).find( "input#in-tribe_events_cat-8" ).prop( "checked", true );
// Uncomment this line to also make Event Category ID 31 checked by default
//jQuery( ce_event_cats ).find( "input#in-tribe_events_cat-31" ).prop( "checked", true );
});
</script>
<?php
}