我正在尝试在WordPress中设置一个自定义的帖子类型“staff”(我过去在其他网站上做了很多次),但当我尝试查看自定义帖子类型的edit.php列表时WordPress仪表板,列表中显示的帖子是使用内置帖子类型“post”的帖子,而不是帖子类型“staff” .
换句话说,[MyWordPressSite] /wp-admin/edit.php?post_type=staff显示post_type ='post'的帖子,而不是post_type ='staff'的帖子 . All和Published旁边括号中的数字是post_type ='staff'帖子的正确数量,但显然与列出的帖子不匹配 .
这是我用于register_post_type的代码:
add_action( 'init', 'staff_init' );
function staff_init() {
$labels = array(
'name' => 'Staff' ,
'singular_name' => 'Staff Member' ,
'menu_name' => 'Staff' ,
'name_admin_bar' => 'Staff' ,
'add_new' => 'Add New Staff' ,
'add_new_item' => 'Add New Staff Member' ,
'new_item' => 'New Staff Member' ,
'edit_item' => 'Edit Staff Member' ,
'view_item' => 'View Staff Member' ,
'all_items' => 'All Staff Members' ,
'search_items' => 'Search Staff Members' ,
'not_found' => 'No staff members found.' ,
'not_found_in_trash' => 'No staff members found in trash.'
);
$args = array(
'labels' => $labels,
'description' => 'Staff Members' ,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' )
);
register_post_type( 'staff', $args );
}
我已经尝试禁用网站上的每个插件,运行 flush_rewrite_rules()
(几次),并将帖子类型的名称更改为1000%确定的其他地方没有使用,但似乎没有任何帮助 .
1 回答
问题解决了 . 在我的functions.php深处,有一个函数正在使用
set_query_var
将post_type
变量重置为'post'
(这样工作人员就不会is_admin()
进行is_admin()
测试 .