2016-05-13 13 views
0

thisの記事に基づいて、私のウェブサイトでカスタムフロントエンドの公開用フォームを使用しています。フロントエンドの公開がフロントエンドのページで機能しない

このコードをページ内に配置すると完全に機能しますが、フロントエンドページ(ホームページ)の場合は機能しません。フォームを送信すると、archive.phpにリダイレクトされます私のフォームで選択したpost_categoryのアーカイブページ。

'post_category' => array($_POST['cat']) 

    <!-- post Category --> 
    <fieldset class="category"> 
    <label for="cat">Catégorie :</label> 
    <?php wp_dropdown_categories('tab_index=10&taxonomy=category&hide_empty=0&show_option_all=Choisissez une catégorie'); ?> 
    </fieldset> 

誰もがなぜ他のすべてのページで動作しますが、フロントページで動作しないのか知っていますか?ここ

は私のPHPコードです:

<?php 
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 'veuillez entrer un titre'; 
    } 
    if (isset ($_POST['description'])) { 
    $description = $_POST['description']; 
    } else { 
    echo 'veuillez entrer du texte'; 
    } 

    $genre = $_POST['genre']; 
    $tranche_age = $_POST['tranche_age']; 

    // 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 
    //'tax_input' => array('regions' => '14'), 
    'post_status' => 'publish',   // Choose: publish, preview, future, draft, etc. 
    'post_type' => 'post', //'post',page' or use a custom post type if you want to 
    //'genre' => $genre, 
    //'tranche_age' => $tranche_age, 
); 


    //SAVE THE POST 
    $pid = wp_insert_post($new_post); 



    wp_set_post_terms($pid,array($_POST['regions']),'regions',true); 
    wp_set_post_terms($pid,array($_POST['sexes']),'sexes',true); 
    wp_set_post_terms($pid,array($_POST['ages']),'ages',true); 


    //REDIRECT TO THE NEW POST ON SAVE 
    $link = site_url(); 
    wp_redirect($link); 

    //ADD OUR CUSTOM FIELDS 
    //add_post_meta($pid, 'genre', $genre, true); 
    //add_post_meta($pid, 'tranche_age', $tranche_age, true); 


} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM 

//POST THE POST YO 
do_action('wp_insert_post', 'wp_insert_post'); 

?> 

    <div id="container"> 
     <div id="content" role="main"> 

    <!-- FRONT END PUBLISHING --> 

    <div class="wpcf7"> 
    <form id="new_post" name="new_post" method="post" action="" class="wpcf7-form" enctype="multipart/form-data"> 
     <!-- post name --> 
     <fieldset name="name"> 
     <label for="title">Titre:</label> 
     <input type="text" id="title" value="" tabindex="5" name="title" /> 
     </fieldset> 

     <!-- post Category --> 
     <fieldset class="category"> 
     <label for="cat">Catégorie :</label> 
     <?php wp_dropdown_categories('tab_index=10&taxonomy=category&hide_empty=0&show_option_all=Choisissez une catégorie'); ?> 
     </fieldset> 

     <!-- post regions --> 
     <fieldset class="regions"> 
     <label for="regions">Région :</label> 
     <?php wp_dropdown_categories('name=regions&tab_index=10&taxonomy=regions&hide_empty=0&show_option_all=Choisissez une catégorie'); ?> 
     </fieldset> 

     <!-- post Content --> 
     <fieldset class="content"> 
     <label for="description">Question :</label> 
     <textarea id="description" tabindex="14" name="description" cols="80" rows="10"></textarea> 
     </fieldset> 

     <!-- Genre --> 
     <input type="hidden" id="sexes" name="sexes" value="26" /> 


     <!-- Tranche d'âge --> 
     <?php $date_of_birth = um_user('birth_date'); $age = CalculateAge($date_of_birth); ?> 

     <?php if ($age >= 18 && $age <= 25) :?> 

     <input type="hidden" value="28" id="ages" name="ages" /> 

     <?php endif; ?> 

     <?php if ($age >= 26 && $age <= 35) :?> 

     <input type="hidden" value="29" id="ages" name="ages" /> 

     <?php endif; ?> 

     <?php if ($age >= 36 && $age <= 45) :?> 

     <input type="hidden" value="30" id="ages" name="ages" /> 

     <?php endif; ?> 

     <?php if ($age >= 46) :?> 

     <input type="hidden" value="31" id="ages" name="ages" /> 

     <?php endif; ?> 





     <fieldset class="submit"> 
     <input type="submit" value="Envoyer" tabindex="40" id="submit" name="submit" /> 
     </fieldset> 

     <input type="hidden" name="action" value="new_post" /> 
     <?php wp_nonce_field('new-post'); ?> 
    </form> 
</div> 

</div> 
</div> 
+0

はあなたの家は、カスタムホームページテンプレートやindex.phpのでしょうか? –

+0

こんにちは、私の家はカスタムテンプレートのページです。それはワードプレスのページで、私はバックオフィスでこのページをフロントページとして使うことを定義しました。私はまた、 "archive.php"と "search.php"の中にwp_insert_postを追加すると、この問題が発生していることに気づきました。あなたはアイディアを持っていますか? – mmdwc

+0

これは私のために働いた –

答えて

0

使用フォームアクション

action="<?php bloginfo('url'); ?>" 
+0

あなたの返信に感謝しますが、それは動作していません...任意のアイデアはありますか?私はこれを追加する必要がありますか?

mmdwc

+0

ホームページテンプレートを共有してください。 –

関連する問題