将类别另存为插入帖子

时间:2014-06-12 作者:Mateusz Winnicki

我有个问题$_POST 类别。我得到了这样的东西:

    // ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
\'post_title\'    =>  $title,
\'post_content\'  =>  $description,
\'post_category\' =>  array($_POST[\'cat\']),   // Usable for custom taxonomies too
\'tags_input\'    =>  array($tags),
\'post_status\'   =>  \'draft\',           // Choose: publish, preview, future, draft, etc.
\'post_type\' =>  \'post\'  //\'post\',page\' or use a custom post type if you want to
);
以及关于分类的代码:

    <!-- post Category -->
<fieldset class="category">
    <label for="cat">Type:</label>
    <select name="cat" id="categories">
    <?php 
$categories = get_categories(\'tab_index=10&taxonomy=category&orderby=name&hide_empty=0&include=6,7,8,9,10\');
foreach ($categories as $category) {
$option = \'<option name ="\'.$category->category_nicename.\'" value="\'.$category->category_nicename.\'">\';
$option .= $category->cat_name;
$option .= \'</option>\';
echo $option;
}
  ?>
 </select>
</fieldset>
但是,如果我使用wp dropdown categories 这很有效,但我需要name 用于选项。wp dropdown categories 不提供名称本身。有没有人知道我错过了什么?

已编辑*

所以,毕竟它是如此简单

 <!-- post Category -->
<fieldset class="category">
    <label for="cat">Type:</label>
    <select name="cat" id="categories">
    <?php 
$categories = get_categories(\'tab_index=10&taxonomy=category&orderby=name&hide_empty=0&include=6,7,8,9,10\');
foreach ($categories as $category) {
$option = \'<option name ="\'.$category->category_nicename.\'" value="\'.$category->term_id.\'">\';
$option .= $category->cat_name;
$option .= \'</option>\';
echo $option;
}
  ?>
 </select>
</fieldset>

1 个回复
最合适的回答,由SO网友:leromt 整理而成

post\\u类别的数组需要是一个整数数组,而不是一个字符串,这就是您从$\\u post[\'cat\'中获得的编写方式。将选项中的值改为类别id。

结束