Skip to content

Instantly share code, notes, and snippets.

@0v3rth3d4wn
Created May 29, 2014 06:52
Show Gist options
  • Save 0v3rth3d4wn/2ccc778b07032301a6f9 to your computer and use it in GitHub Desktop.
Save 0v3rth3d4wn/2ccc778b07032301a6f9 to your computer and use it in GitHub Desktop.
Save and add new post
/**
* Publish and go to add new post or CPT
* @param int $post_id The Post id
* @return void
*/
function save_and_new( $post_id ) {
$cpt = ( $_POST['post_type'] !== 'post') ? $_POST['post_type'] : false;
if ( isset( $_POST['publish'] ) || isset( $_POST['save'] ) ) {
if($cpt) {
wp_redirect( admin_url( 'post-new.php?post_type=' . $cpt ) );
exit;
} else {
wp_redirect( admin_url( 'post-new.php' ) );
exit;
}
}
}
add_action( 'save_post', 'save_and_new' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment