我创建了一个自定义的帖子类型(称为赞助者),并连接了一个额外的分类法,称为“类型”。
一切基本上都很完美,但我非常希望我的分类法“Type”是一个下拉菜单,而不是通常的“Type和search或create a new”。原因是,我在分类法中创建了六种不同的“类型”,而要创建新“赞助商”的人应该只需要为每个新的赞助商帖子选择这六种类型中的一种。
我试过谷歌提供的一些教程和指南,但没有一个能奏效。
自定义帖子类型和自定义分类由插件“自定义帖子类型UI”创建。
到目前为止,我尝试的是:
add_action(\'restrict_manage_posts\',\'my_restrict_manage_posts\');
function my_restrict_manage_posts() {
global $typenow;
if ($typenow==\'sponsors\'){
$args = array(
\'show_option_all\' => "Show All Categories",
\'taxonomy\' => \'type\',
\'name\' => \'type\'
);
wp_dropdown_categories($args);
}
}
add_action( \'request\', \'my_request\' );
function my_request($request) {
if (is_admin() && $GLOBALS[\'PHP_SELF\'] == \'/wp-admin/edit.php\' && isset($request[\'post_type\']) && $request[\'post_type\']==\'sponsors\') {
$request[\'term\'] = get_term($request[\'type\'],\'type\')->name;
}
return $request;
}
还有这个add_action( \'restrict_manage_posts\', \'my_restrict_manage_posts\' );
function my_restrict_manage_posts() {
// only display these taxonomy filters on desired custom post_type listings
global $typenow;
if ($typenow == \'sponsors\' || $typenow == \'type\') {
// create an array of taxonomy slugs you want to filter by - if you want to retrieve all taxonomies, could use get_taxonomies() to build the list
$filters = array(\'title_sponsor\', \'platin-sponsor\', \'guld-sponsor\', \'diamant-sponsor\');
foreach ($filters as $tax_slug) {
// retrieve the taxonomy object
$tax_obj = get_taxonomy($tax_slug);
$tax_name = $tax_obj->labels->name;
// retrieve array of term objects per taxonomy
$terms = get_terms($tax_slug);
// output html for taxonomy dropdown filter
echo "<select name=\'$tax_slug\' id=\'$tax_slug\' class=\'postform\'>";
echo "<option value=\'\'>Show All $tax_name</option>";
foreach ($terms as $term) {
// output each select option line, check against the last $_GET to show the current option selected
echo \'<option value=\'. $term->slug, $_GET[$tax_slug] == $term->slug ? \' selected="selected"\' : \'\',\'>\' . $term->name .\' (\' . $term->count .\')</option>\';
}
echo "</select>";
}
}
}
但正如我所说,没有一个是有效的。如有任何帮助或建议,将不胜感激。
真诚的感谢-梅斯蒂卡