在wp_insert_post上获取500(内部服务器错误)
问题描述:
我需要一些帮助,即时尝试使用htmlform(php和wordpress)执行wp_insert_post
。我不断收到500服务器错误,我不明白为什么,你能帮我吗? (印刷品和回声是用于测试一些东西)。 在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');
?>
<!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,$ description?当代码到达'$ new_post = array'行时,可能变量不存在。
,如果你设置你的代码是这样的顶级变量会发生什么:
$title = 'This is my title';
$message = 'This is my message';
$description = 'This is my description';
是否得救?
当在wordpress环境之外使用wordpress代码时,您需要首先加载wordpress引擎。你必须做'require_once('path/to/wp/root/wp-load.php');' – 2015-03-02 12:18:18