Title: Adding events through code
Last modified: August 31, 2016

---

# Adding events through code

 *  Resolved [19fra91](https://wordpress.org/support/users/19fra91/)
 * (@19fra91)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/adding-events-through-code/)
 * Hi,
    I need to add some event manually through php and I found this:
 *     ```
       $EM_Event = new EM_Event();
       $EM_Event->event_name = $evt_name;
       $EM_Event->event_start_date = $evt_start_d;
       $EM_Event->event_start_time = $evt_start_t;
       $EM_Event->event_end_date = $evt_end_d;
       $EM_Event->event_end_time = $evt_end_t;
       $EM_Event->start = strtotime($EM_Event->event_start_date." ".$EM_Event->event_start_time);
   
       $EM_Event->end = strtotime($EM_Event->event_end_date." ".$EM_Event->event_end_time);
       $EM_Event->event_all_day = $evt_all_day;
       $EM_Event->recurrence = $evt_rec;
       $EM_Event->recurrence_freq = $evt_rec_freq;
       $EM_Event->recurrence_interval = $evt_rec_int;
       $EM_Event->recurrence_byweekno = $evt_rec_weekno;
       $EM_Event->recurrence_byday = 3;//$evt_rec_byday;
       $EM_Event->recurrence_days = 0;//$evt_rec_days;
       $EM_Event->save();
       ```
   
 * This seems that it doesn’t work because I don’t find new events added manually.
 * Can someone help me to understand where I wrong?
 * Thank you
 * [https://wordpress.org/plugins/events-manager/](https://wordpress.org/plugins/events-manager/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [caimin_nwl](https://wordpress.org/support/users/caimin_nwl/)
 * (@caimin_nwl)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/adding-events-through-code/#post-7217420)
 * Hi,
 * How are you using this code?
 *  [fersamp](https://wordpress.org/support/users/fersamp/)
 * (@fersamp)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/adding-events-through-code/#post-7217426)
 * Hi, I’m using this code in my function.php file, do you think that problem is
   the invocation?
 * I would like to create some event dinamically passing variables through a function,
   for example start date, end date and title like this:
 *     ```
       $EM_Event = new EM_Event();
       $EM_Event->event_name = $evt_name;
       $EM_Event->event_start_date = $evt_start_d;
       $EM_Event->event_start_time = $evt_start_t;
       $EM_Event->event_end_date = $evt_end_d;
       $EM_Event->event_end_time = $evt_end_t;
       $EM_Event->save();
       ```
   
 * If I get some data like title, start and end date, how can I create manually 
   events? That code doesn’t work form me
 *  Plugin Support [angelo_nwl](https://wordpress.org/support/users/angelo_nwl/)
 * (@angelo_nwl)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/adding-events-through-code/#post-7217479)
 * not sure if this will help you out but maybe you can try – [http://pastebin.com/3UDjZ8Le](http://pastebin.com/3UDjZ8Le)

Viewing 3 replies - 1 through 3 (of 3 total)

 The topic ‘Adding events through code’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.gif?rev=3711454)
 * [Events Manager - Calendar, Bookings, Tickets, Appointments and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

 * 3 replies
 * 4 participants
 * Last reply from: [angelo_nwl](https://wordpress.org/support/users/angelo_nwl/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/adding-events-through-code/#post-7217479)
 * Status: resolved