I have a front end form users use to create custom posts. It works fine with Chrome and FF, but when in Safari two posts are created.
The code i'm using is below. I've tried a few conditionals shown in other answers but none worked. How can I prevent wp_insert_post from creating duplicate posts when submitted from Safari?
Thanks
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_post") {
$tags = $_POST['post_tags'];
$new_post = array(
'post_title' => $title,
'post_content' => $description,
'post_category' => array($_POST['cat']),
'tags_input' => array($tags),
'post_status' => 'publish',etc.
'post_type' => 'website'
);
global $current_user;
get_currentuserinfo();
$user_name = strtolower($current_user->user_login); //custom caps will default to lowercase anyway
$pid = wp_insert_post($new_post);
update_post_meta($pid, "s2member_ccaps_req", $user_name, true);
wp_redirect( get_permalink($pid) );
exit();
The form
<form id="new_post" name="new_post" method="post" action="">
<!-- post name -->
<p><label for="title">Title</label><br />
<input type="text" id="title" value="" tabindex="1" size="20" name="title" />
</p>
<!-- post Category -->
<p><label for="Category">Category:</label><br />
<p><?php wp_dropdown_categories( 'tab_index=3&taxonomy=category' ); ?></p>
<!-- post Content -->
<p><label for="description">Content</label><br />
<textarea id="description" tabindex="4" name="description" cols="50" rows="6"></textarea>
</p>
<!-- post tags -->
<p><label for="post_tags">Tags:</label>
<input type="text" value="" tabindex="5" size="16" name="post_tags" id="post_tags" /></p>
<p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>
<input type="hidden" name="action" value="new_post" />
<?php wp_nonce_field( 'new-post' ); ?>
</form>
$pid
to make sure it's a valid ID before you callupdate_post_meta
?var_dump($pid);
it returned int(280) after trying to submit another post it returned int(282) the posts are being created just fine, it's just from Safari two posts are created