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 );
}
}