Skip to content

Instantly share code, notes, and snippets.

@moskowite
Created January 27, 2012 00:11
Show Gist options
  • Save moskowite/1686055 to your computer and use it in GitHub Desktop.
Save moskowite/1686055 to your computer and use it in GitHub Desktop.
<?php
function __update_post_meta( $post_id, $field_name, $value = '' ) {
if ( empty( $value ) OR ! $value ) {
delete_post_meta( $post_id, $field_name );
} elseif ( ! get_post_meta( $post_id, $field_name ) ) {
add_post_meta( $post_id, $field_name, $value );
} else {
update_post_meta( $post_id, $field_name, $value );
}
}
$post = array(
'post_content' => $_POST['content'], //The full text of the post.
'post_title' => $_POST['title'], //The title of your post.
'post_author' => 1, //for live change to: 604631
'post_status' => 'draft',
'post_type' => 'post'
);
$postId = wp_insert_post( $post );
wp_upload_bits($_POST["image"]["name"], null, file_get_contents($_POST["image"]["tmp_name"]));
__update_post_meta( $postId, 'author', $_POST['author'] );
__update_post_meta( $postId, 'author_email', $_POST['author_email'] );
__update_post_meta( $postId, 'author_bio', $_POST['author_bio'] );
__update_post_meta( $postId, 'link', $_POST['link'] );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment