列出自定义帖子类型中的下拉类型
-
22-10-2019 - |
题
我有三种自定义帖子类型,每种都有大约5个分类法和2种自定义帖子类型共享两个分类法。
除了在下拉列表的部分以外,我几乎已经设置了从前端发布的所有内容,以显示post_types。
由于现在是前端发布的作品,但是,由于其中没有自定义帖子类型,因此网址被打破了,我已经搜索了各地,并且可以在列出自定义帖子类型上找到零...可以完成吗?
关于马丁
编辑:只是偶然发现了这个 在codex上,,
解决方案
对不起,这感觉有些奇怪地回答自己的问题,但是您走了。
首先声明变量:( customStategory)
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_post_types函数创建掉落的掉线:
<?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>';
?>