我有一个网站,有一些自定义的帖子类型。这些都以非常相似的方式注册,共享大多数属性:
const ARGS = [
\'hierarchical\' => true,
//\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 5,
\'show_in_admin_bar\' => true,
\'show_in_nav_menus\' => true,
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
//\'publicly_queryable\' => true,
\'capability_type\' => \'page\',
\'show_in_rest\' => false,
];
例如,CPT
order
和
person
都是这样注册的
private static function register_order()
{
$args = array_merge(
[
\'label\' => __( \'order\', \'X\' ),
\'labels\' => [...],
\'supports\' => [\'title\', \'editor\', \'author\'],
],
self::ARGS
);
register_post_type( \'order\', $args );
}
private static function register_person()
{
$args = array_merge(
[
\'label\' => __( \'person\', \'X\' ),
\'labels\' => [...],
\'supports\' => [\'title\', \'author\'],
],
self::ARGS
);
register_post_type( \'person\', $args );
}
然而,在wp admin中,我目前只看到
person
s鉴于
order
s给我一个空列表。
通过调试栏和查询监视器对此进行调试,我得到以下主要查询
order
(修订了
post_status
对于两个查询)
SELECT wp_posts.ID, wp_posts.post_parent
FROM wp_posts
WHERE 1=1
AND (wp_posts.ID = \'0\')
AND wp_posts.post_type = \'order\'
AND (...)
ORDER BY wp_posts.menu_order ASC, wp_posts.post_title ASC
和的查询
person
是
SELECT wp_posts.ID, wp_posts.post_parent
FROM wp_posts
WHERE 1=1
AND wp_posts.post_type = \'person\'
AND (...)
ORDER BY wp_posts.menu_order ASC, wp_posts.post_title ASC
现在我对SQL有了足够的了解
AND (wp_posts.ID = \'0\')
是我没有得到任何结果的原因。我只是不知道它为什么会在那里。我没有
pre_get_posts
钩子集,停用除此之外的所有插件,没有任何更改。