自定义帖子不会出现在Posts ->所有的帖子在管理菜单


Custom Posts not appearing under Posts -> All Posts in admin menu

我已经创建了一个自定义的帖子类型'Products',它在仪表板上显示为一个单独的类别'Products'。我正在遵循一些关于如何编辑自定义帖子的说明,它告诉我通过帖子->所有帖子编辑它们,以便我可以将自定义字段作为屏幕视图的一部分,但是当我访问"所有帖子"时,我没有看到任何我的"产品"帖子实例。所有的帖子-自定义和标准-应该出现在所有的帖子?当我设置我的"产品"帖子时,我做错了什么吗?

 <?php
function create_product_post_type() {
  $labels = array(
   'name'           => 'Products',
   'singular_name'  => 'Product'
  );
  $args = array(
   'labels'     => $labels,
   'public'     => true,
   'supports'   => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
   'taxonomies' => array( 'category' )
  );
  register_post_type( 'product', $args ); 
}
add_action( 'init', 'create_product_post_type' );
function add_product_to_archives( $wp_query ) {
    $types_array = array( 'post', 'product' );
    if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
        set_query_var( 'post_type', $types_array );
    }
}
add_action('pre_get_posts', 'add_product_to_archives');
?>

"Posts"与您自定义的帖子类型"Products"不同,因此它不会出现在"Posts"菜单中。您的自定义帖子类型将有自己的自定义管理菜单。