我一直在尝试为wordpress帖子构建一个前端表单 . 我使用自定义帖子类型,但不是自定义分类,这些工作正常 .

我正在使用wp_insert_post函数执行此操作,尝试发布 Headers ,发布内容,让用户在7个特定类别之间进行选择,并让他们选择创建最多5个标记 . Headers 和帖子内容工作正常,但我不能发布类别和标签 .

我已经尝试在post_category和category_name中创建一个数组,具有特定的ID和/或slugs并在表单上插入,但没有成功 .

这是functions.php上的自定义帖子类型:

function custom_post_type_historia() {
    register_post_type('historia', array(
        'label' => 'Histórias',
        'description' => 'Histórias',
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'capability_type' => 'post',
        'map_meta_cap' => true,
        'has_archive' => true,
        'hierarchical' => false,
        'rewrite' => array('slug' => 'historia', 'with_front' => true),
        'query_var' => true,
        'supports' => array('title', 'editor', 'page-attributes','post-formats'),
        'taxonomies' => array('post_tag','category'),

        'labels' => array (
            'name' => 'Histórias',
            'singular_name' => 'História',
            'menu_name' => 'Histórias',
            'add_new' => 'Adicionar Nova',
            'add_new_item' => 'Adicionar Novo História',
            'edit' => 'Editar',
            'edit_item' => 'Editar História',
            'new_item' => 'Nova História',
            'view' => 'Ver História',
            'view_item' => 'Ver História',
            'search_items' => 'Procurar Histórias',
            'not_found' => 'Nenhuma História Encontrado',
            'not_found_in_trash' => 'Nenhuma História Encontrado no Lixo',
            'has_archive' => true,
        )
    ));
}
add_action('init', 'custom_post_type_historia');

这是我的PHP:

<?php

if( isset($_POST['submit']) ) {

global $user_ID;

$insert_post = array(
    'post_title' => $_POST['post_title'],
    'post_content' => $_POST['post'],
    'post_status' => 'pending',
    'post_date' => date('Y-m-d H:i:s'),
    'post_author' => $user_ID,
    'post_type' => 'historia',
    // 'category_name' => array("item1", "item2", "item3", "item4", "item5", "item6", "item7")
    'post_category' => array(1, 2, 3, 4, 5, 6, 7),
    'post_tag' => $_POST['post_tag']
);

wp_insert_post($insert_post);

  }

?>

这是形式:

<form action="" method="post">


<table border="1" width="200">
    <tr>
      <td><label for="post_title">Post Title</label></td>
      <td><input name="post_title" type="text" /></td>
    </tr>
    <tr>
      <td><label for="post">Post</label></td>
      <td><input name="post" type="text" /></td>
    </tr>
    <tr>
      <td><label for="post_tag">tag</label></td>
      <td><input name="post_tag" type="text" /></td>
    </tr>
    <tr>
      <td><label for="post_category">Q</label></td>
      <td><input type="checkbox" name="category_name[7]" value="7" id="category" /></td>
    </tr>

  </table>

  <input name="submit" type="submit" value="submit" />
</form>

Apreciate所有的帮助