0
我直接使用本教程中的代碼:http://voodoopress.com/how-to-post-from-your-front-end-with-no-plugin/。在本地設置時,重定向工作正常。當完全相同的站點託管在機架空間雲網站上時,它不會。這是怎麼回事?wp_redirect函數在本地工作,但不在服務器上
值得注意片:
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中,並且無濟於事。任何想法可能是什麼問題?
這是一個很好的想法,但它是'POST'後調用的'wp_redirect',所以我認爲這不適用。 – alexvance