dongshen9058 2015-03-02 12:13
浏览 50

在wp_insert_post上获得500(内部服务器错误)

I need some help, im trying to do a wp_insert_post with a htmlform (php and wordpress). I keep getting a 500 server error and i dont understand why, can you please help me? (the prints and echoes is for testing some stuff).

<?php
    print_r($_POST);
    
    if( 'POST' == $_SERVER['REQUEST_METHOD'] ){
        print((isset ($_POST['title1'])));
        // Do some minor form validation to make sure there is content
        if (isset ($_POST['title1'])) {
            $title =  $_POST['title1'];
        } else {
            echo 'fyll i';
        }
        if (isset ($_POST['description'])) {
            $description = $_POST['description'];
        } else {
            echo 'fyll i';
        }
         if (isset ($_POST['message'])) {
            $message = $_POST['message'];
        } else {
            echo 'fyll i';
        }
        $tags = $_POST['post_tags'];
        echo('ny entry');
    
        print_r($new_post);
    
        $new_post = array(
           'post_title'    => $title,
           'post_content' => $message,
           'post_name'  => $description,
           'post_status'   => 'publish',
           'post_type' => 'omdmen'
            
        );
    
        print_r($new_post);
        $new_post = wp_insert_post($new_post); 
    
    }    
    
    echo('finished');

?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <div id="postbox">
    <form id="new_post" name="new_post" method="post" action="votepost.php">
        <p><label for="title">Ide</label><br />
            <input type="text" id="title" value="" tabindex="1" size="20" name="title1" />
        </p>
        <p><label for="description">Hantverk</label><br />
            <input type="text" id="description" value="" tabindex="1" size="20" name="description" />
        </p>
        <p><label for="message">Budskap</label><br />
            <input type="text" id="message" value="" tabindex="1" size="20" name="message" />
        </p>
        <input type="submit" value="OK" tabindex="6" id="submit" name="submit" />
    </form>
</div>
    </body>
</html>

$title,
       'post_content' =&gt; $message,
        'post_name'  =&gt; $description,
        'post_status'   =&gt; 'publish',
        'post_type' =&gt; 'omdmen'

    );

print_r($new_post);
    $new_post = wp_insert_post($new_post); 

}    

echo('finished');

?>

  • 写回答

1条回答 默认 最新

  • dtvp3625 2015-03-02 12:46
    关注

    Are the $title, $description elsewhere in the code initiated? When the code reached the '$new_post = array' line maybe the variables doesn't exists.

    What happens if you set the variables on the top of your code like this:

    $title = 'This is my title';
    $message = 'This is my message';
    $description = 'This is my description';
    

    Does it get saved?

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度