我有一个用户用来创建自定义帖子的前端表单。它可以与Chrome和FF配合使用,但在Safari中会创建两个帖子。
下面是我使用的代码。我试过其他答案中的一些条件句,但都不起作用。从Safari提交时,如何防止wp\\U insert\\U post创建重复的帖子?
谢谢
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();
表格
<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>