du42561 2018-03-26 15:15
浏览 81

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

I create website where unregistered users can save different ad from fronted. Now it just test study where i try insert data to wp_posts and wp_term_relationships tables. I hard wrote 'post_category' => array(3) just for test.

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 :

<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>

I just want save post in wp_posts table with relationships in wp_term_relationships table.

  • 写回答

1条回答 默认 最新

  • doutao1171 2018-03-26 16:16
    关注

    Your $post array's post_type should probably be post.

    评论

报告相同问题?

悬赏问题

  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)