我直接使用本教程中的代码:http: //voodoopress.com/how-to-post-from-your-front-end-with-no-plugin/。在本地设置时,重定向工作正常。当完全相同的站点托管在机架空间云站点上时,它不会。这是怎么回事?
值得注意的一块:
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_post") {
// Do some minor form validation to make sure there is content
if (isset ($_POST['title'])) {
$title = $_POST['title'];
} else {
echo 'Please enter the wine name';
}
if (isset ($_POST['description'])) {
$description = $_POST['description'];
} else {
echo 'Please enter some notes';
}
$tags = $_POST['post_tags'];
// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
'post_title' => $title,
'post_content' => $description,
'post_category' => array($_POST['cat']), // Usable for custom taxonomies too
'tags_input' => array($tags),
'post_status' => 'publish', // Choose: publish, preview, future, draft, etc.
'post_type' => 'post' //'post',page' or use a custom post type if you want to
);
//SAVE THE POST
$pid = wp_insert_post($new_post);
//SET OUR TAGS UP PROPERLY
wp_set_post_tags($pid, $_POST['post_tags']);
//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');`
这很简单。该代码使用wp_insert_post
并随后重定向到该帖子的链接发布帖子。一切都很好,它适用于我的 XAMPP 设置。但问题是:我无法对它进行任何排列以在实时服务器上工作。我已经开始多次安装新的 WP,只将此代码放在 home.php 中,但无济于事。知道到底是什么问题吗?