gpt4 book ai didi

php - 保存新帖子时,我无法在 wp_term_relationships 表中插入自定义类别

转载 作者:行者123 更新时间:2023-11-29 17:49:40 26 4
gpt4 key购买 nike

我创建了一个网站,未注册的用户可以在其中保存不同的广告。现在它只是测试研究,我尝试将数据插入到 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 表中。

最佳答案

您的 $post 数组的 post_type 可能应该是 post

关于php - 保存新帖子时,我无法在 wp_term_relationships 表中插入自定义类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49494923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com