我使用的是根基岩+鼠尾草9 Beta 3。我已经创建了一个类型为的自定义帖子lp
我想设置为我的主页。下面是我使用的代码:
function cptui_register_my_cpts_lp() {
/**
* Post Type: Landing Pages.
*/
$labels = array(
"name" => __( \'Landing Pages\', \'sage\' ),
"singular_name" => __( \'Landing Page\', \'sage\' ),
);
$args = array(
"label" => __( \'Landing Pages\', \'sage\' ),
"labels" => $labels,
"description" => "Pages without menus and/or totally custom layouts.",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => false,
"show_in_menu" => true,
"exclude_from_search" => true,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => [ "slug" => "lp", "with_front" => true ],
"query_var" => true,
"menu_icon" => "dashicons-welcome-widgets-menus",
"supports" => [ "title", "thumbnail", "excerpt" ],
);
register_post_type( "lp", $args );
}
add_action( \'init\', \'cptui_register_my_cpts_lp\' );
我已安装
mpress-custom-front-page 但它似乎没有看到我的登录页。
所以,通过一些挖掘,我注意到它使用get_posts()
获取帖子的步骤post_type = \'any\'
.
它发送的查询是这样的:
$queried_post = get_posts([
\'posts_per_page\' => - 1,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'post_type\' => \'any\',
\'post_status\' => \'publish\',
]);
此查询返回除我的自定义帖子类型之外的所有帖子:
如果我重做这个精确的查询,但是post_type
到\'lp\'
然后我得到了我的帖子,没问题:
为什么会any
找不到我的自定义帖子类型