Title: Programatically Create and Update Events
Last modified: July 12, 2023

---

# Programatically Create and Update Events

 *  Resolved Anonymous User 13711045
 * (@anonymized-13711045)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/)
 * What is the proper way to programatically add and update events? The `tribe_create_event`
   function doesn’t work. The event is created but doesn’t show on the frontend.
   The documentation is pretty poor for this area.
    -  This topic was modified 2 years, 10 months ago by Anonymous User 13711045.

Viewing 15 replies - 1 through 15 (of 27 total)

1 [2](https://wordpress.org/support/topic/programatically-create-and-update-events/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/programatically-create-and-update-events/page/2/?output_format=md)

 *  Thread Starter Anonymous User 13711045
 * (@anonymized-13711045)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-16890798)
 * It appears that this is a known issue and I am not the only one experiencing 
   it as evidence by another thread.
 * [https://wordpress.org/support/topic/events-calendar-time-date-wont-update/](https://wordpress.org/support/topic/events-calendar-time-date-wont-update/)
 * No support person ever responded to that with a solution or even acknowledged
   that there is an issue, so I’m hoping to get some clarity on why the `tribe_create_event`
   and `tribe_update_event` functions do not properly work.
 *  Plugin Contributor [Matthew Batchelder](https://wordpress.org/support/users/borkweb/)
 * (@borkweb)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-16890858)
 * Howdy, @thekendog! We have some documentation around working with events (querying,
   creating, deleting, etc) programmatically over at [https://docs.theeventscalendar.com](https://docs.theeventscalendar.com).
   Check out the [ORM documentation](https://docs.theeventscalendar.com/apis/orm/),
   specifically info on [event creation](https://docs.theeventscalendar.com/apis/orm/basics/#modifying-the-database).
 * Hopefully this is helpful for you!
 *  Thread Starter Anonymous User 13711045
 * (@anonymized-13711045)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-16890859)
 * How do I add/edit/update them? That page is for filtering. Where are all of the
   variables I can use? The link on that page doesn’t even work! It goes to a page
   not found!
 * [https://docs.theeventscalendar.com/apis/orm-basics/#modifying-the-database](https://docs.theeventscalendar.com/apis/orm-basics/#modifying-the-database)
 * Also, why is the `tribe_create_event` function still included in the plugin and
   in the documentation if it doesn’t work?
    -  This reply was modified 2 years, 10 months ago by Anonymous User 13711045.
    -  This reply was modified 2 years, 10 months ago by Anonymous User 13711045.
    -  This reply was modified 2 years, 10 months ago by Anonymous User 13711045.
 *  Plugin Contributor [Matthew Batchelder](https://wordpress.org/support/users/borkweb/)
 * (@borkweb)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-16890957)
 * Ah! You found a broken link – which I have now fixed, thank you. The link you
   found that was broken was that second one in my reply to you labeled “event creation”.
   I’ve added some documentation around the fields that can be used for adding /
   editing events on that Modifying the Database link.
 * The tribe_create_event is still present because it is still applicable to folks
   that have had TEC active pre 6.0 and have not migrated their events. The arguments
 *  Plugin Contributor [Matthew Batchelder](https://wordpress.org/support/users/borkweb/)
 * (@borkweb)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-16890960)
 * If you are curious about where to poke further from a code perspective, check
   out our automated tests around the ORM. We have a number of tests that show the
   usage as well! In the TEC repo on GitHub, you can see them here:
    - [Events](https://github.com/the-events-calendar/the-events-calendar/tree/master/tests/wpunit/Tribe/Events/ORM/Events)
    - [Organizers](https://github.com/the-events-calendar/the-events-calendar/tree/master/tests/wpunit/Tribe/Events/ORM/Organizers)
    - [Venues](https://github.com/the-events-calendar/the-events-calendar/tree/master/tests/wpunit/Tribe/Events/ORM/Venues)
 * As you are working on programmatic tweaking of events, this might have some helpful
   things to see / take into consideration as you work with the events.
    -  This reply was modified 2 years, 10 months ago by [Matthew Batchelder](https://wordpress.org/support/users/borkweb/).
 *  Thread Starter Anonymous User 13711045
 * (@anonymized-13711045)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-16891175)
 * Ok, perhaps making note in the [documentation](https://docs.theeventscalendar.com/reference/functions/tribe_create_event/)
   that the `tribe_create_event` function doesn’t work anymore will help others.
   I wasted way too much time today trying to figure out what the heck was going
   on.
 * As for the new methods, I have gotten the create method to work. However, the
   update one is not. I’m doing this:
   `$event_id = tribe_events()->where('id', $
   post_id)->set('start_date', '2023-07-29 00:00:00)->set('end_date', '2023-07-31
   23:59:59)->set('timezone', 'America/New_York)->save();
 * These are the erros I get in the debug log:
 * `tribe-canonical-line channel=default level=debug source="TEC\Events\Custom_Tables\
   V1\Models\Model::validate:266" errors="{\"end_date\":\"The start_date should 
   be a valid date.\",\"timezone\":\"The provided timezone is not a valid timezone.\",\"
   start_date_utc\":\"The start_date_utc requires a value.\"}"`
 * `tribe-canonical-line channel=default level=error source="The start_date should
   be a valid date. : The provided timezone is not a valid timezone. : The start_date_utc
   requires a value." method="TEC\Events\Custom_Tables\V1\Models\Builder::upsert"
   line=306 model="TEC\Events\Custom_Tables\V1\Models\Event"`
 *  Plugin Contributor [Matthew Batchelder](https://wordpress.org/support/users/borkweb/)
 * (@borkweb)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-16892671)
 * In the above snippet, it looks like there are missing quotes after each of the
   dates and the timezone. I was able to run an update just like yours and it succeeded
   once I fixed the missing quotes.
 * I have made a note on the `tribe_create_event` documentation to point out the
   ORM, but I took a look at our automated tests and realize that I misspoke. `tribe_create_event`
   should still function and is supported, despite `tribe_events()` being the preferred
   approach (I indicated that on the documentation).
 * The following update worked for me using `tribe_events()` with an event ID of
   5:
 * $event_id = tribe_events()
   ->where('id', $post_id)->set('start_date', '2023-07-
   29 00:00:00')->set('end_date', '2023-07-31 23:59:59')->set('timezone', 'America/
   New_York')->save();
 * The following `tribe_create_event` worked for me as well:
 * tribe_create_event([
    'post_title' => 'Boom', 'post_content' => 'Boom', 'post_status'
   => 'publish', 'EventStartDate' => '2023-08-01', 'EventStartHour' => '12', 'EventStartMinute'
   => '00', 'EventStartMeridian' => 'pm', 'EventEndDate' => '2023-08-01', 'EventEndHour'
   => '01', 'EventEndMinute' => '00', 'EventEndMeridian' => 'pm',]);
 *  Thread Starter Anonymous User 13711045
 * (@anonymized-13711045)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-16892691)
 * The missing quote was just an error in me copying and pasting stuff. They are
   there in my actual code.
 * I figured out the issue and it was that you cannot update an existing event without
   having first created it using the `tribe_create_event` or `tribe_events` method.
   I am using an ACF form on the frontend to create the event by publishing a tribe_events
   post. I was then trying to edit stuff for it using code. This does not work and
   I cannot then use the `tribe_update_event` or `tribe_events` method because the
   event doesn’t have a proper entry in the tec_events and tec_occurences tables
   and it’ll throw an error. This is a huge bummer as it basically disallows creating
   events through ACF forms (I’m using ACF Extended) or Gravity Forms for instance.
   The events are a regular custom post type, but they also have connected custom
   DB tables that are required to have associated entries and you can only access
   them by using the functions and methods provided by the plugin. It’s a hybrid
   approach and kind of weird.
 * I know about the Community Events add-on and I’ve tried it and I hated it. Again,
   a huge bummer.
 *  Thread Starter Anonymous User 13711045
 * (@anonymized-13711045)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-16892732)
 * Also, I did discover what I think is a bug when updating an event using the `
   tribe_events` method.
 * When creating an event, I am supplying a start and end date field without time,
   and am setting all_day to true. This results in proper dates. For instance, the
   supplied start_date on creation is 2023-07-29 which results in a final start 
   date of `2023-07-29 00:00:00`. The supplied end date is 2023-07-30 which results
   in an end date of `2023-07-30 23:59:59`.
 * However, when doing this using the save method, the times are incorrect. Again,
   I am setting all_day to true. However, the final dates are `2023-07-29 00:00:
   00` and `2023-07-30 00:00:00`.
    -  This reply was modified 2 years, 10 months ago by Anonymous User 13711045.
    -  This reply was modified 2 years, 10 months ago by Anonymous User 13711045.
 *  Plugin Contributor [Matthew Batchelder](https://wordpress.org/support/users/borkweb/)
 * (@borkweb)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-16893318)
 * Ah, good findings! This will generate the occurrences after post creation (which
   will then allow tribe_events() to work its magic):
 * tribe()->make( \TEC\Events\Custom_Tables\V1\Repository\Events::class )->update(
   $event_id, [] );
 * This brings up an excellent point that we should create either a helper function
   that allows for the generation/saving of event occurrences and/or do that by 
   default in `tribe_events()` when saving! Thank you for exploring this here.
 * As for that other finding – I’ll pass that info to the team to look into more
   deeply.
 *  Plugin Support [Darian](https://wordpress.org/support/users/d0153/)
 * (@d0153)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-16930428)
 * Hi @thekendog
 * I’m reaching out to let you know that we’ve created an internal ticket to address
   the issue you reported, and we’ve included your case in it.
 * Unfortunately, we don’t have an estimated time for when the issue will be resolved,
   but we’ll keep you updated as soon as a solution becomes available.
 * If you have other questions or concerns, please do not hesitate to bump a new
   thread on our way. This allows us to track topics/issues efficiently and follow
   the[ WordPress Forum Guidelines](https://wordpress.org/support/guidelines/).
 * —
   Internal Bug Ticket Reference: TEC-4855
 *  [Earthman Media](https://wordpress.org/support/users/earthman100/)
 * (@earthman100)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-17049046)
 * Thank you [@borkweb](https://wordpress.org/support/users/borkweb/) !!! That little
   snippet was the silver bullet I was seeking for months now, to fix the cloned
   events that were not appearing in the frontend
 * Tier 1 and Tier 2 support had no clue about it, when I opened a ticket trying
   to determine what I was missing when programmatically creating an event through
   other means
 * Perhaps you can make an internal note of this simple snippet, and add to the 
   ORM documentation, to be of better help to others seeking insights when extending
   the TEC plugin’s functionality?
 * You saved my day, much appreciated!
    -  This reply was modified 2 years, 8 months ago by [Earthman Media](https://wordpress.org/support/users/earthman100/).
 *  Plugin Support [Darian](https://wordpress.org/support/users/d0153/)
 * (@d0153)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-17055061)
 * Hi [@earthman100](https://wordpress.org/support/users/earthman100/)
 * Thanks for your message. and I’m glad the snippets provided above were helpful
   to you.
 * Please see our documentation here:
    - [ORM – Fetching Posts](https://the-events-calendar.github.io/products-engineering/docs/php/orm-fetching-posts/)
    - [ORM – Methods](https://the-events-calendar.github.io/products-engineering/docs/php/orm-methods/)
 *  [Earthman Media](https://wordpress.org/support/users/earthman100/)
 * (@earthman100)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-17055233)
 * Thanks. I had looked into that stuff before – the thing is, the posts were *already
   created, by another plugin.  I had to use the snippet I mentioned, found in this
   forum, nowhere else, to modify them, *after the fact, to get them to appear on
   the frontend.  
 * That method wasn’t/isn’t mentioned on either of the pages you linked to. That’s
   the point I was trying to make… a ‘helper’ function (as [@borkweb](https://wordpress.org/support/users/borkweb/)
   suggested) to use that snippet might be a good idea, for future friendliness
 * FYI – The 1st page you linked to has a dead link to (what used to be) the second
   link:
 * > To see details on this, check out the [Modifying the database](https://the-events-calendar.github.io/docs/php/orm-methods.md#modifying-the-database)
   > section of ORM – Methods
   > [https://the-events-calendar.github.io/docs/php/orm-methods.md#modifying-the-database](https://the-events-calendar.github.io/docs/php/orm-methods.md#modifying-the-database)
 *  Plugin Support [Darian](https://wordpress.org/support/users/d0153/)
 * (@d0153)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/#post-17064109)
 * Hi [@earthman100](https://wordpress.org/support/users/earthman100/)
 * Thank you for letting us know about the documentation issue and the dead link.
   I have already informed the team about it, and we will work on resolving it as
   soon as possible.
 * I will keep you posted on any updates. Your input is greatly appreciated.

Viewing 15 replies - 1 through 15 (of 27 total)

1 [2](https://wordpress.org/support/topic/programatically-create-and-update-events/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/programatically-create-and-update-events/page/2/?output_format=md)

The topic ‘Programatically Create and Update Events’ is closed to new replies.

 * ![](https://ps.w.org/the-events-calendar/assets/icon-256x256.gif?rev=2516440)
 * [The Events Calendar](https://wordpress.org/plugins/the-events-calendar/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/the-events-calendar/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/the-events-calendar/)
 * [Active Topics](https://wordpress.org/support/plugin/the-events-calendar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/the-events-calendar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/the-events-calendar/reviews/)

 * 27 replies
 * 9 participants
 * Last reply from: [shingen0810](https://wordpress.org/support/users/shingen0810/)
 * Last activity: [1 year, 11 months ago](https://wordpress.org/support/topic/programatically-create-and-update-events/page/2/#post-17824413)
 * Status: resolved