Title: Creating event with php
Last modified: August 21, 2016

---

# Creating event with php

 *  [mibarbaroja](https://wordpress.org/support/users/mibarbaroja/)
 * (@mibarbaroja)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/creating-event-with-php/)
 * I need to create a event when an user makes a reservation. I need this happen
   transparent for user and popup or similar is not option for me., because I have
   a php file which send an email to user and need this file add the event to the
   calendar.
 * What’s the correct way to do that? I’m not very advance php developer but i’m
   learning to work with objects.
 * Regards
 * [http://wordpress.org/plugins/all-in-one-event-calendar/](http://wordpress.org/plugins/all-in-one-event-calendar/)

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

 *  Thread Starter [mibarbaroja](https://wordpress.org/support/users/mibarbaroja/)
 * (@mibarbaroja)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/creating-event-with-php/#post-4429151)
 * ok, this is working for me, but perhaps is not the best way.
 *     ```
       // ================
       // = Create post =
       // ================
       $post = array(
         'comment_status' => 'closed', // 'closed' means no comments.
         'ping_status'    => 'closed', // 'closed' means pingbacks or trackbacks turned off
         'post_author'    => 1, //The user ID number of the author.
         'post_category'  => $categories, //post_category no longer exists, try wp_set_post_terms() for setting a post's categories
         'post_content'   => $content, //The full text of the post.
         'post_date'      => $today, //The time post was made.
         'post_date_gmt'  => $todayGMT, //The time post was made, in GMT.
         'post_name'      => $slug, // The name (slug) for your post
         'post_status'    => 'private',
         'post_title'     => $name,
         'post_type'      => 'ai1ec_event',
         'tax_input'      => array( 'taxonomy_name' => array( 'events_categories' ) ) // support for custom taxonomies.
       );  
   
       $post_id = wp_insert_post( $post, $wp_error );
   
       $columns = array(
       	'post_id'          => $post_id,
       	'start'            => $start,
       	'end'              => $end,
       	'allday'           => 0,
       	'contact_name'     => $contact_name,
       	'contact_phone'    => $contact_phone,
       	'contact_email'    => $contact_email,
       	'ical_uid'         => 1
       );
   
       $format = array(
       	'%d',
       	'FROM_UNIXTIME( %d )',
       	'FROM_UNIXTIME( %d )',
       	'%d',
       	'%s',
       	'%s',
       	'%s',
       	'%s',
       );
   
       $table_name = $wpdb->prefix . 'ai1ec_events';
   
       if( $post_id )
       	{
       	if( ! $update ) {
       		// =========================
       		// = Insert new event data =
       		// =========================
       		$wpdb->query( $wpdb->prepare(
       			"INSERT INTO $table_name ( " .
       			join( ', ', array_keys( $columns ) ) .
       			" ) VALUES ( " .
       			join( ', ', $format ) .
       			" )",
       			$columns ) );
       	} else {
       		// ==============================
       		// = Update existing event data =
       		// ==============================
       		$where         = array( 'post_id' => $post_id );
       		$where_escape  = array( '%d'                        );
       		$wpdb->update( $table_name, $columns, $where, $format, $where_escape );
       	}
       }
       ```
   
 *  Thread Starter [mibarbaroja](https://wordpress.org/support/users/mibarbaroja/)
 * (@mibarbaroja)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/creating-event-with-php/#post-4429164)
 * I have a problem with the date format… I’m using “Y-m-d H:i:s”
 * Suggestions?

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

The topic ‘Creating event with php’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/all-in-one-event-calendar.svg)
 * [Timely All-in-One Events Calendar](https://wordpress.org/plugins/all-in-one-event-calendar/)
 * [Support Threads](https://wordpress.org/support/plugin/all-in-one-event-calendar/)
 * [Active Topics](https://wordpress.org/support/plugin/all-in-one-event-calendar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/all-in-one-event-calendar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/all-in-one-event-calendar/reviews/)

## Tags

 * [add event](https://wordpress.org/support/topic-tag/add-event/)
 * [create event](https://wordpress.org/support/topic-tag/create-event/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 2 replies
 * 1 participant
 * Last reply from: [mibarbaroja](https://wordpress.org/support/users/mibarbaroja/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/creating-event-with-php/#post-4429164)
 * Status: not resolved