Create a gist now

Instantly share code, notes, and snippets.

<!-- New Post Form -->
<div id="postbox">
<form id="new_post" name="new_post" method="post" action="">
<p><label for="submitter">Submitted By</label><br />
<input type="text" id="submitter" value="" tabindex="1" size="20" name="submitter" />
<p><label for="email">Email Address</label><br />
<input type="text" id="email" value="" tabindex="2" size="20" name="email" />
<p><label for="title">Song Title</label><br />
<input type="text" id="title" value="" tabindex="3" size="20" name="title" />
<p><label for="composer">Composed By</label><br />
<input type="text" id="composer" value="" tabindex="5" size="20" name="composer" />
<p><label for="performer">Performed By</label><br />
<input type="text" id="performer" value="" tabindex="5" size="20" name="performer" />
<p><label for="tablature">Song Body</label><br />
<textarea id="tablature" tabindex="6" name="tablature" cols="50" rows="6"></textarea>
<p><select name="categories" size="1" tabindex="7">
<option value="8">Hawaiian Mele</option>
<option value="9">Local Jams</option>
<option value="6">Personal Songs</option>
<option value="7">Tablature</option>
<p align="right"><input type="submit" value="Publish" tabindex="8" id="submit" name="submit" /></p>
<input type="hidden" name="action" value="new_post" />
<?php wp_nonce_field( 'new-post' ); ?>
<!--// New Post Form -->
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && ($_POST['action']== 'new_post')) {
$has_errors = false;
if (isset ($_POST['title'])) {
$title = $_POST['title'];
} else {
echo 'Please enter a song title';
$has_errors = true;
if (isset ($_POST['performer'])) {
$performer = $_POST['performer'];
} else {
echo 'Please enter a performer';
$has_errors = true;
if (isset ($_POST['composer'])) {
$composer = $_POST['composer'];
} else {
echo 'Please enter a composer';
$has_errors = true;
if (isset ($_POST['tablature'])) {
$tablature = $_POST['tablature'];
} else {
echo 'Please enter the content';
$has_errors = true;
$tags = $_POST['post_tags'];
if (!$has_errors){
//save <title> by: <performer>
$title .= " by ".$performer = $_POST['title'];
//save Composed by: <composer> Performed by: <performer> <tablature>
$content = "<h4>Composed by: ". $composer."</h4><br/><h4>Performed by: ".$performer."</h4><br/>".$tablature;
$new_post = array(
'post_title' => $title,
'post_content' => $content,
'post_category' => $_POST['cat'],
'tags_input' => $tags,
'post_status' => 'draft'
$pid = wp_insert_post($new_post);
//save email and submmiter as post meta in custom fields
update_post_meta($pid, 'submitter_email', urldecode($_POST['email']));
update_post_meta($pid, 'submitter_name', urldecode($_POST['submitter']));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment