【问题标题】:Custom Post Type posts not listing in Dashboard自定义帖子类型帖子未在仪表板中列出
【发布时间】:2016-04-13 10:01:09
【问题描述】:

我正在尝试在 WordPress 中设置自定义帖子类型“员工”(过去我在其他网站上做过很多次),但是当我尝试查看自定义帖子的 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% 确定没有在其他任何地方使用的名称,但似乎没有帮助。

【问题讨论】:

    标签: php wordpress custom-post-type


    【解决方案1】:

    问题解决了。在我的functions.php 深处,有一个函数使用set_query_varpost_type 变量重置为'post'(这样工作人员就不会包含在存档页面中),但没有@987654324 @测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      • 2016-07-24
      • 2013-07-14
      • 2011-12-16
      • 2015-03-15
      • 1970-01-01
      相关资源
      最近更新 更多