Event Counter

Home Forums Calendar Products Events Calendar PRO Event Counter

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #251089
    cnh
    Participant

    Is it possible to execute a function right after submitting an event? I want to increase a counter when a user will submit an event.

    Thanks.

    #253231

    Hi!

    Thanks for reaching out to us and I would be more than happy to help you with your question.

    We have tried to make The Events Calendar as extensible as possible. For this purpose we have several action hooks built into the event life-cycle including ‘tribe_events_event_save‘.

    You can add actions on this hook to execute your own functions when a new event has been created.

    The WordPress Codex has documentation on how to use action hooks that may be of use to you.
    http://codex.wordpress.org/Function_Reference/do_action

    Our documentation page also contains additional information on hooks and filters.

    Please let me know if this answers your question.

    #262944
    cnh
    Participant

    I’ve tried with hook with my custom function but my function is not executing when an event is submitted. I’ve added the following codes in the functions.php file:

    function my_func(){
    update_usermeta( 33, ‘previous_member_level’, ‘test’ );
    }

    do_action(‘tribe_events_event_save’,’my_func’);

    Let me know if you need more details. Thanks

    #264357

    Hi!

    Looking at the link I sent earlier I may have caused you some slight confusion, my apologies.

    The do_action function is where you execute any functions defined to the action hook. We use this in our code base to create the hooks.

    To add a function for execution based on the action you want to use add_action. I’ve updated the sample you provided as below, please let me know if it works for you.

    function my_func(){
        update_usermeta( 33, ‘previous_member_level’, ‘test’ );
    }
    
    add_action(‘tribe_events_event_save’,'my_func’);
    

    – Matthew

    #278219
    cnh
    Participant

    Thanks. It is almost working. But this action also executes when an event is updated. Is there any action exists like ‘tribe_events_event_submit’ or ‘tribe_events_event_create’ which will execute only when an event is first created not updated?

    Thanks.

    #299549

    Hi!

    I did another review of the code base and unfortunately there is no explicit hook for when an Event is “created”. We have hooks for explicit creation of Venue and Organizer but not for an Event.  I’m going to add this to our tracker as it seems like an oversight.

    Until the team has a chance to look into why we don’t have a created hook separately from save you could potentially use the modified time stamp of the event to see if it is the original save.

    function my_func( $eventId ) {
    $event = get_post( $eventId );
    if ($event->post_date != $event->post_modified) return;
    // Place your code here
    }
    }

    Please let me know if the above works for you and I’ll follow-up on my end to see about getting a distinct hook created.

    Thank you,

    – Matthew

    #470862

    Hi, I wanted to quickly follow-up with you to see if you are all set. Please let me know if you do have additional questions I can assist with or if I should go ahead and close this thread.

    Thank you,

    – Matthew

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Event Counter’ is closed to new replies.