发布带有自定义分类的新帖子的表单

时间:2012-12-04 作者:FAWAZ

enter image description here

我已经在下拉列表中显示了自定义分类法,正如您在红色框中看到的一样,我想问一下如何将它们与帖子一起提交。我想不出来`

// Do some minor form validation to make sure there is content
if (isset ($_POST[\'title\'])) {
    $title =  $_POST[\'title\'];
} else {
    echo \'Please enter the wine name\';
}

// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
\'post_title\'    =>  $title,
\'tax_input\' => array(
    \'industries\' =>  $_REQUEST[\'taxonomy_id\'] ),
\'post_status\'   =>  \'publish\',           // Choose: publish, preview, future, draft, etc.
\'post_type\' =>  \'websites\'  //\'post\',page\' or use a custom post type if you want to
);

//SAVE THE POST
$pid = wp_insert_post($new_post);

//SET OUR TAGS UP PROPERLY

//REDIRECT TO THE NEW POST ON SAVE
$link = get_permalink( $pid );
wp_redirect( $link );

} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM

//POST THE POST YO
do_action(\'wp_insert_post\', \'wp_insert_post\');?>`

the form

enter code here

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

更新表单以包含术语id,而不仅仅是<input type="checkbox" /> 使用<input type="checkbox" name="taxonomy_id[]" value="\'. $industryterm->term_id .\'" />. 这样,您实际上是在发送一些值,在本例中是术语id。

在args中wp_insert_post() 确保包括以下内容:

\'tax_input\' => array(
    \'industries\' => $_REQUEST[\'taxonomy_id\']
)

结束

相关推荐

Programmatically adding posts

我将要创建一个解析器,它将插入新的自定义帖子。所以,这很简单global $user_ID; $new_post = array( \'post_title\' => \'My New Post\', \'post_content\' => \'Lorem ipsum dolor sit amet...\', \'post_status\' => \'publish\', \'post_date\' => da