2013-04-11 47 views
1

我正嘗試從Wordpress的前端進行發佈。我在一個名爲page-submit.php的頁面中有以下代碼,雖然它已工作,但在提交頁面時我收到404錯誤,但我不知道爲什麼或如何跟蹤此問題。運行此頁面時出現Wordpress 404錯誤

此頁page_submit.php顯示正常,位於我的主題文件夾中。

有什麼建議嗎?

<?php get_header(); ?> 

<?php 

// Check if the form was submitted 
if('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action'])) { 

// Do some minor form validation to make sure there is content 
if (isset ($_POST['title'])) { 
    $title = $_POST['title']; 
} else { 
    echo 'Please enter a title'; 
} 
if (isset ($_POST['description'])) { 
    $description = $_POST['description']; 
} else { 
    echo 'Please enter the content'; 
} 
$tags = $_POST['post_tags']; 

// Add the content of the form to $post as an array 
$post = array(
    'post_title' => $title, 
    'post_content' => $description, 
    'post_category' => $_POST['cat'], // Usable for custom taxonomies too 
    'tags_input' => $tags, 
    'post_status' => 'publish',   // Choose: publish, preview, future, etc. 
    'post_type'  => $_POST['post_type'] // Use a custom post type  if you want to 
); 
wp_insert_post($post); // Pass the value of $post to WordPress the insert function 
         // http://codex.wordpress.org/Function_Reference/wp_insert_post 

wp_redirect(home_url()); // redirect to home page after submit 

} // end IF 
// Do the wp_insert_post action to insert it 
do_action('wp_insert_post', 'wp_insert_post'); 
?> 



<!-- New Post Form --> 
<div id="postbox"> 
<form id="new_post" name="new_post" method="post" action=""> 

    <p><label for="title">Title</label><br /> 
    <input type="text" id="title" value="" tabindex="1" size="20" name="title"  /> 
    </p> 
    <p><label for="description">Description</label><br /> 
    <textarea id="description" tabindex="3" name="description" cols="50" rows="6"></textarea> 
    </p> 
    <p><?php wp_dropdown_categories('show_option_none=Category&tab_index=4&taxonomy=category'); ?></p> 
    <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="post_type" id="post_type" value="post" /> 
    <input type="hidden" name="action" value="post" /> 
    <?php wp_nonce_field('new-post'); ?> 
</form> 
</div> 
<!--// New Post Form --> 


<?php get_sidebar(); ?> 

<?php get_footer(); ?> 

回答

2

它看起來像你的POST變量是由WordPress的保留。請使用「title_x」,「description_x」和「post_tags_x」,而不是「title」,「description」和「post_tags」。

+0

謝謝,我只是試過這個沒有區別。我實際上發現帖子現在也沒有插入。 – Jeff

+0

進一步的調查顯示了不同地區的錯誤 - 關閉此主題 – Jeff