来自前端的带有自定义字段的帖子提交不起作用

时间:2012-08-12 作者:IFightCode

我正在从fronted提交帖子,它有一些自定义字段。我使用ShortCodeAPI在任何页面/帖子中使用该表单。应在下面找到代码。但在提交表单后,什么都没有发生,表单返回。我需要你的帮助。

<?php
//Shortcode API
function apl_video(){
global $current_user;
get_currentuserinfo();
if (!isset($_POST[\'submit\'])) {

?>
<form name="new_post" method="post" action="">

    <table border="0" align="center">
        <tr><td><label for="id_meta">Video Title</label></td><td><input id="post_title" tabindex="1" type="text" name="post_title"/></td></tr>

        <tr><td><label for="vid_wid">Video Width</label></td><td><input id="vid_wid" tabindex="2" type="text" name="vid_wid"/></td></tr>

        <tr><td><label for="vid_hei">Video Height</label></td><td><input id="vid_hei" tabindex="3" type="text" name="vid_hei"/></td></tr>

        <tr><td><label for="vid_ply">Autoplay</label></td><td><select tabindex="4" name="vid_ply" id="vid_ply">
        <option value="Yes">Yes</option>
        <option value="No">No</option>
        </select>
      </td></tr>

        <tr><td><label for="vid_ski">Skin</label></td><td><select tabindex="5" name="vid_ski" id="vid_ski">
        <option value="player1">Player 1</option>
        <option value="player2">Player 2</option>
        </select>
      </td></tr>


        <tr>
          <td><label for="vid_you">Youtube Video Link</label></td>
          <td><input id="vid_you" tabindex="6" type="text" name="vid_you"/></td>
        </tr>
        <tr>
          <td><label for="vid_mp4">MP4 Video Link</label></td>
          <td><input id="vid_mp4" tabindex="7" type="text" name="vid_mp4"/></td>
        </tr>
        <tr>
          <td><label for="vid_ogg">OGG Video Link</label></td>
          <td><input id="vid_hei" tabindex="8" type="text" name="vid_ogg"/></td>
        </tr>
        <tr>
          <td><label for="vid_web">WEBM Video Link</label></td>
          <td><input id="vid_hei" tabindex="9" type="text" name="vid_web"/></td>
        </tr>
        <tr>
          <td><label for="vid_pst">Poster Image Link</label></td>
          <td><input id="vid_hei" tabindex="10" type="text" name="vid_pst"/></td>
        </tr>
        <tr>

            <td>&nbsp;</td>

            <?php wp_nonce_field( \'new-post\' ); ?>

            <td><input type="submit" value="Generate" name="submit"/></td>

        </tr>

    </table>



</form>

<?php }

else {
    $title      =   esc_attr($_POST[\'post_title\']);
    $vid_wid    =   esc_attr($_POST[\'vid_wid\']);
    $vid_hei    =   esc_attr($_POST[\'vid_hei\']);
    $vid_ply    =   esc_attr($_POST[\'vid_ply\']);
    $vid_ski    =   esc_attr($_POST[\'vid_ski\']);
    $vid_you    =   esc_attr($_POST[\'vid_you\']);
    $vid_mp4    =   esc_attr($_POST[\'vid_mp4\']);
    $vid_web    =   esc_attr($_POST[\'vid_web\']);
    $vid_ogg    =   esc_attr($_POST[\'vid_ogg\']);
    $vid_pst    =   esc_attr($_POST[\'vid_pst\']);


    global $user_ID;

    $new_post = array(
            \'post_title\'    => $title,
            \'post_status\'   => \'publish\',
            \'post_type\'     => \'video\',
            \'post_date\'     => date(\'Y-m-d H:i:s\'),
            \'post_author\'   => $user_ID,
    );

    //save the new post
    $pid    =   wp_insert_post($new_post);

    // Do the wp_insert_post action to insert it
    do_action(\'wp_insert_post\', \'wp_insert_post\'); 

    add_post_meta($pid, \'vid_wid\', $vid_pst, true);
    add_post_meta($pid, \'vid_hei\', $vid_hei, true);
    add_post_meta($pid, \'vid_ply\', $vid_ply, true);
    add_post_meta($pid, \'vid_ski\', $vid_ski, true);
    add_post_meta($pid, \'vid_you\', $vid_you, true);
    add_post_meta($pid, \'vid_ogg\', $vid_ogg, true);
    add_post_meta($pid, \'vid_web\', $vid_web, true);
    add_post_meta($pid, \'vid_mp4\', $vid_mp4, true);
    add_post_meta($pid, \'vid_pst\', $vid_pst, true);



    //Result
    echo \'Done\';



        }
}


add_shortcode( \'wpvideogen\', \'apl_video\' );

1 个回复
最合适的回答,由SO网友:Milo 整理而成

假设您实际上有一个video 但是,有几件事你可以纠正-

短代码应return 它们的值,否则您将看到短代码内容出现在任何帖子内容之前,而不是您实际放置短代码的位置。

  • do_action(\'wp_insert_post\', \'wp_insert_post\'); 是不必要的,wp_insert_post 已经在函数中执行了该操作,因此您将调用它两次。

  • 结束

    相关推荐