Set custom event meta

Home Forums Calendar Products Community Events Set custom event meta

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #812367
    louisecote
    Participant

    Hello.

    I’ve added two custom meta fields (‘_EventCreationDate’,’_EventAdPeriod’,) to The Events Calendar Class (the-events-calendar.class.php).
    I want to set these fields, when user clicks Submit button on Community Events page (/events/community/add).
    I guess I need to edit Submission_Handler.php, maybe save() function.
    I tried using this line of code, but it doesn’t work.
    TribeEventsAPI::saveEventMeta( $this->event_id, array(“_EventCreationDate”=>”2014″,”_EventAdPeriod”=>”12”));

    #813014
    Barry
    Member

    Hi louisecote,

    Customizations are really something we need to leave in your hands, but I’d be happy to point you in the right direction if I can 🙂

    I’ve added two custom meta fields (‘_EventCreationDate’,’_EventAdPeriod’,) to The Events Calendar Class (the-events-calendar.class.php).

    Modifying core plugin code is rarely a good idea and not something we’d generally recommend. Perhaps you could implement your modifications without doing this?

    I want to set these fields, when user clicks Submit button on Community Events page (/events/community/add).

    WordPress itself has some useful hooks you can use such as save_post_{post_type} so you could consider listening out for the appropriate action firing and add your logic to a plugin of its own (or possibly to your theme’s functions.php file).

    Since you probably only want to add these fields to events submitted via Community Events you could additionally test against the ecp_event_submission nonce which is used to protect that form, ie:

    add_action( 'init', 'setup_community_submissions_marker' );
    
    function setup_community_submissions_marker() {
    	if ( class_exists( 'TribeEvents' ) )
    		add_action( 'save_post_' . TribeEvents::POSTTYPE, 'mark_community_submissions' );
    }
    
    function mark_community_submissions( $post_id ) {
    	if ( ! wp_verify_nonce( @$_POST['_wpnonce'], 'ecp_event_submission' ) ) return;
    	update_post_meta( $post_id, 'your_custom_field', 'some_value' );
    }

    Would that work for you?

    #813837
    louisecote
    Participant

    Thanks, this is exactly what I was looking for!

    #814095
    Barry
    Member

    Awesome 🙂

    I’ll go ahead and close this thread but if we can help with anything else please don’t hesitate to open a new one and let us know – one of the team will be only too happy to help.

    Last but not least, if you have a moment to spare we’d love to hear your thoughts on The Events Calendar so far over on our plugin review page – thanks again!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Set custom event meta’ is closed to new replies.