default category from frontend

Home Forums Calendar Products Community Events default category from frontend

  • This topic has 14 replies, 4 voices, and was last updated 7 years ago by Ivan.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1231915
    Ivan
    Participant

    Hi, so i would like users who summit from frontend to post in a default category, is there a way to do that?

    #1232707
    Ivan
    Participant

    So, I found this thread in the forum https://theeventscalendar.com/support/forums/topic/exclude-a-category-from-community-events-form/

    that seems to solve the problem I have… but I don’t understand in wich file I have to put the code

    <?php
    add_filter( 'get_terms_defaults', 'community_events_remove_category_option', 10, 2 );
    /**
     * Prevent specific categories from displaying as options in the Community Events Submission form
     * 
     * Subsitute the IDs of the categories that you would like to exclude from the array on line #16  below
     */
    function community_events_remove_category_option( $defaults, $taxonomies ) {
    	if( ! in_array( 'tribe_events_cat', $taxonomies ) )
    		return $defaults;
    	if( tribe_is_event_query() )
    		return $defaults;
    	$defaults['exclude'] = array(4);
    	return $defaults;
    }
    #1233138
    Hunter
    Moderator

    Hello 🙂

    My apologies for the delayed response, I was working with another support team member to come up with a working snippet which will set categories by default. Here is a link to the snippet. You will need to add it to the bottom of your theme’s functions.php file. You’ll most likely need to remove the opening php tag, which looks like this:

    <?php

    Please let me know how it goes and if you get stuck, try doing some general web searches on adding code to a WordPress functions.php file. Have a great weekend!

    #1233426
    Ivan
    Participant

    thanks for the answer… but it does not totally solves my problem… because users can still uncheck the default category and choose another… is’nt there a way yo not show the category selection in the frontend form and make it autoselect only the default one?

    thanks!

    #1233969
    Hunter
    Moderator

    Hey Ivan 🙂

    Thanks for the update. It might actually be best to use CSS to “hide” the category section, then use the following snippet to assign a default category:

    /* Tribe, assign a category after a Community Events submission is saved */
    function tribe_ce_force_category ( $event_id ) {
    wp_set_object_terms( $event_id, 'community', Tribe__Events__Main::TAXONOMY );
    }
    add_action( 'tribe_community_event_created', 'tribe_ce_force_category' );

    Let me know how it works out. Cheers!

    #1234080
    Ivan
    Participant

    I don’t actually know what to do… I can read css, but don’t really know how to code… I tried putting the code in the themes css, in the plugin css… but is not working… can you explain me better in wich file I have to put the code?

    #1234756
    Hunter
    Moderator

    Sure! Try adding it to the bottom of your theme’s functions.php file. Be sure to make a backup of the functions.php file before making any changes. Let me know how it goes!

    #1234773
    Ivan
    Participant

    done, but is not working, I still see

    #1237662
    Hunter
    Moderator

    Could you possible share your functions.php file with me? Pastebin.com is a free tool where you can paste the code and share a link with me. Feel free to send it as a private reply.

    Thanks 🙂

    #1238115
    Ivan
    Participant

    This reply is private.

    #1239211
    Hunter
    Moderator

    Thank you for sharing the link with me. Try removing line 264, which contains the following code, then save your changes and let me know how it works:

    <?php

    #1239796
    Ivan
    Participant

    This reply is private.

    #1242503
    Hunter
    Moderator

    My apologies, I somehow missed that line was a necessary part of your functions.php file. After further inspection, it appears you’ve added it correctly. Another route to “hiding” the category section from the CE add event form is to use something along the lines of:

    jQuery( ce_event_cats ).find( "input#in-tribe_events_cat-8" ).prop( "checked", true ).hide();

    Please review this article on how to implement custom jQuery. Unfortunately you’ll need to handle this customization yourself. For what is covered in the support forums, please review our What support is provided for license holders? Knowledgebase article.

    Best of luck and it might also be a good idea to submit your request to our UserVoice Feature Ideas. Have a great week ahead. Cheers!

    #1253885
    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 ‘default category from frontend’ is closed to new replies.