我创建了一个网站,未注册的用户可以从前端保存不同的广告。现在它只是测试研究,我尝试将数据插入wp_posts和wp_term_relationships表。 我辛苦写了'post_category'=> array(3)仅供测试。
if( isset($_POST['submit']) && wp_verify_nonce( $_POST['name_of_nonce_field'], 'name_of_my_action' )){
if (isset ($_POST['title'])) {
$title = $_POST['title'];
} else {
echo 'Please enter a title';
}
if (isset ($_POST['description'])) {
$description = $_POST['description'];
} else {
echo 'Please enter the content';
}
$post = array(
'post_title' => $title,
'post_content' => $description,
'post_status' => 'pending',
'post_type' => 'category',
'post_category' => array(3),
);
wp_insert_post($post); // Pass the value of $post to WordPress the insert function
wp_redirect( home_url() );
exit;
}
html表格:
<form name="new_post" method="post" action="">
<p><label class="form__title" for="title"></label><br />
<input class="form__title-input" type="text" size="20" name="title" />
</p>
<div class="form-group">
<label for="exampleSelect1">Example select</label>
<select class="form-control" id="exampleSelect1" name="category">
<?php foreach ($terms as $el) :?>
<?php echo "<option>". $el->name. "</option>" ?>
<?php endforeach; ?>
</select>
</div>
<?php foreach ($customTags as $el) :?>
<div class="form-check form-check-inline">
<?php echo '<input class="form-check-input" name"check_list" type="checkbox" id="'.$el->term_id. '" value="ZAGlushKa">'?>
<?php echo '<label class="form-check-label" for="inlineCheckbox1">'.$el->name.'</label>'?>
</div>
<?php endforeach; ?>
<p><label class="form__title" for="description">About You</label><br />
<textarea class="form__content-area" name="description" cols="50" rows="6"></textarea>
</p>
<p><label class="form__title"></label><br />
<input class="form__title-input" type="text" value="" size="16" name="post_tags"/>
</p>
<p><input class="form__submit" type="submit" value="Publish" name="submit" /></p>
<input type="hidden" name="post_type" id="post_type" value="professionals" />
<input type="hidden" name="action" value="post" />
<?php wp_nonce_field( 'name_of_my_action', 'name_of_nonce_field' );?>
</form>
我只想在wp_posts表中保存帖子,并在wp_term_relationships表中显示关系。
答案 0 :(得分:0)
您的$ post数组的post_type
应该是post
。