很抱歉,回答自己的问题感觉有点奇怪,但给你。。。。
首先声明变量:(customcategory)
global $userdata;
$errors = array();
$title = trim($_POST[\'wpuf_post_title\']);
$customcategory = trim($_POST[\'customcategory\']);
$content = trim($_POST[\'wpuf_post_content\']);
$tags = wpuf_clean_tags($_POST[\'wpuf_post_tags\']);
$cat = trim($_POST[\'cat\']);
其次,用于添加帖子的数组:
if (!$errors) {
$frontend_post = array(
\'post_title\' => $title,
\'post_content\' => $content,
\'post_status\' => $post_status,
\'post_author\' => $userdata->ID,
\'post_category\' => array($_POST[\'cat\']),
\'post_type\' => $customcategory,
\'tags_input\' => $tags
);
$post_id = wp_insert_post($frontend_post);
最后通过get\\u post\\u types函数创建dropcrown:
<?php
$args=array(
\'public\' => true,
\'_builtin\' => false
);
$output = \'names\';
$operator = \'and\';
$post_types=get_post_types($args,$output,$operator);
echo \'<select name="customcategory">\';
foreach ($post_types as $post_type ) {
echo \'<option value="\'. $post_type.\'">\'. $post_type. \'</option>\';
}echo \'</select>\';
?>