我有一个自定义帖子类型的博客,如:
register_post_type( 'type',
array(
'labels' => array(
'name' => __( 'Types' ),
'singular_name' => __( 'Type' )
),
'public' => true,
'has_archive' => true,
)
);
显然,这包含在一个由 init 操作调用的函数中。问题是这个帖子类型充满了帖子,超过 1K,但在存档页面 (domain.com/type) 上没有显示任何内容。我试图验证查询,但查询显示为 NULL。有人有可靠的解决方案吗?
PS - 这就是我讨厌 wordpress 的原因。永远不能正常工作。
标签:wordpress-broken-again, wordpress-sucks, wordpress-i-hate-you
全文摘录:
function cp_init_types() {
register_post_type( 'nursing-home',
array(
'labels' => array(
'name' => __( 'Nursing Homes' ),
'singular_name' => __( 'Nursing Home' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'nursing-homes', 'with_front' => true ),
/*'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail' ),
'publicly_queryable' => true,
'exclude_from_search'=> false,
'taxonomies' => array('category','post_tag'),*/
)
);
flush_rewrite_rules( false );
}
function add_my_post_types_to_query( $query ) {
if(is_category() || is_tag() || is_home() && empty( $query->query_vars['suppress_filters'] ) ) {
$post_type = get_query_var('post_type');
if($post_type) {
$post_type = $post_type;
}
else {
$post_type = array('post','nursing-home','nav_menu_item');
}
$query->set('post_type', $post_type);
return $query;
}
return $query;
}
// Show posts of 'post', 'page' and 'movie' post types on home page
add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
add_action("init", "cp_init_types");