自定义帖子未显示在帖子下 - >管理菜单中的所有帖子

时间:2016-09-28 19:45:34

标签: php wordpress post

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

 <?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');

?>

1 个答案:

答案 0 :(得分:1)

“帖子”是与自定义帖子类型“产品”不同的帖子类型,因此它不会显示在“帖子”菜单中。您的自定义帖子类型将有自己的自定义管理菜单。