• 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/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mibarbaroja

    (@mibarbaroja)

    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

    (@mibarbaroja)

    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.