Skip to content

Instantly share code, notes, and snippets.

@joedolson
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joedolson/79cb891bf9f65f10f23e to your computer and use it in GitHub Desktop.
Save joedolson/79cb891bf9f65f10f23e to your computer and use it in GitHub Desktop.
Add My Calendar Events as Blog Posts
add_action( 'mc_save_event', 'my_event_post', 10, 3 );
function my_event_post( $action, $data, $new_event ) {
// if the event save was successful.
if ( $action == 'add' ) {
$title = $data['event_title'];
$content = "[my_calendar_event event='$new_event' template='details' list='']";
$post_status = 'publish';
$auth = $data['event_author'];
$type = 'post';
$my_post = array(
'post_title' => $title,
'post_content' => $content,
'post_status' => 'draft',
'post_author' => $auth,
'post_name' => sanitize_title( $title ),
'post_date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
'post_type' => $type
);
$post_id = wp_insert_post( $my_post );
wp_publish_post( $post_id );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment