我有一个自定义帖子类型的博客,如:
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");
答案 0 :(得分:0)
您是否从手册中注意到了这一点:
同样可以使用单个帖子及其档案进行显示 single.php和archive.php模板文件分别为
自定义帖子类型的单个帖子将使用single-{post_type} .php和 他们的档案将使用archive- {post_type} .php,其中{post_type}是 register_post_type()函数的$ post_type参数。
答案 1 :(得分:0)
您明确声明您只需要重写规则的软刷新。要获取自定义帖子类型以显示您需要在.htaccess
文件中使用一些重写规则。使用硬冲洗,你可以让WordPress为你添加。从通话中删除false
参数。
flush_rewrite_rules(); // pass no parameters and it defaults to true