我需要一些帮助,我试图用htmlform(php和wordpress)做wp_insert_post
。我一直收到500服务器错误,我不明白为什么,你能帮我吗? (印刷品和回声用于测试一些东西)。
<?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');
?>
&#13;
<!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>
&#13;
$标题, &#39; POST_CONTENT&#39; =&GT; $消息, &#39; POST_NAME&#39; =&GT; $描述, &#39; post_status&#39; =&GT; &#39;发布&#39 ;, &#39; post_type&#39; =&GT; &#39; omdmen&#39; ); 的print_r($ new_post); $ new_post = wp_insert_post($ new_post); } 回波(&#39;成品&#39); ?&GT;
答案 0 :(得分:0)
代码中其他位置的$ title,$ description是否已启动?当代码到达'$ new_post = array'行时,变量可能不存在。
如果您在代码顶部设置变量,会发生什么:
$title = 'This is my title';
$message = 'This is my message';
$description = 'This is my description';
它会被保存吗?