Created
February 7, 2014 18:06
-
-
Save cameronbaney/8868317 to your computer and use it in GitHub Desktop.
Add a new post to WordPress from outside the dashboard with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "update_form") { | |
$membername = $_POST['membername']; | |
if($_POST['title']){ | |
$post_title = $_POST['title']; | |
} else { | |
$post_title = 'update'; | |
} | |
// ADD THE FORM INPUT TO $new_post ARRAY | |
$new_post = array( | |
'post_title' => $post_title, | |
'post_content' => $update, | |
'post_status' => 'publish', | |
'post_type' => 'post', | |
'member_name' => $membername, | |
'tags_input' => $membername | |
); | |
//SAVE THE POST | |
$pid = wp_insert_post($new_post); | |
add_post_meta($pid, 'author', $membername, true); | |
add_post_meta($pid, 'post_title', $post_title, true); | |
//REDIRECT TO THE NEW POST ON SAVE | |
/*$link = get_permalink( $pid ); | |
wp_redirect( $link );*/ | |
} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM | |
//POST THE POST YO | |
do_action('wp_insert_post', 'wp_insert_post'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment