admin管理员组文章数量:1130349
I have a site with a few custom post types. Those are all registered in a very similar fashion sharing most attributes:
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,
];
For example the CPTs order and person are registered like this
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 );
}
However, when in the wp-admin, I currently only see persons whereas orders gets me an empty list.
Debugging this with the Debug Bar and Query Monitor, I get the following main query for order (redacted the post_status for both queries)
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
And the query for person is
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
Now I understand SQL good enough to know that this line
AND (wp_posts.ID = '0')
is the reason I don't get any results. I just don't have any idea why it is there. I don't have any pre_get_posts hook set, deactivated all plugins except this one, no change whatsoever.
I have a site with a few custom post types. Those are all registered in a very similar fashion sharing most attributes:
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,
];
For example the CPTs order and person are registered like this
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 );
}
However, when in the wp-admin, I currently only see persons whereas orders gets me an empty list.
Debugging this with the Debug Bar and Query Monitor, I get the following main query for order (redacted the post_status for both queries)
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
And the query for person is
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
Now I understand SQL good enough to know that this line
AND (wp_posts.ID = '0')
is the reason I don't get any results. I just don't have any idea why it is there. I don't have any pre_get_posts hook set, deactivated all plugins except this one, no change whatsoever.
1 Answer
Reset to default 1As mmm pointed out in the comments, order should not be used as a name for a custom post type, as it may "interfere with other WordPress functions". Read more in the Codex:
Reserved Post Types The following post types are reserved and used by WordPress already.
postpageattachmentrevisionnav_menu_itemcustom_csscustomize_changesetIn addition, the following post types should not be used as they interfere with other WordPress functions.
actionauthorordertheme
I have a site with a few custom post types. Those are all registered in a very similar fashion sharing most attributes:
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,
];
For example the CPTs order and person are registered like this
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 );
}
However, when in the wp-admin, I currently only see persons whereas orders gets me an empty list.
Debugging this with the Debug Bar and Query Monitor, I get the following main query for order (redacted the post_status for both queries)
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
And the query for person is
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
Now I understand SQL good enough to know that this line
AND (wp_posts.ID = '0')
is the reason I don't get any results. I just don't have any idea why it is there. I don't have any pre_get_posts hook set, deactivated all plugins except this one, no change whatsoever.
I have a site with a few custom post types. Those are all registered in a very similar fashion sharing most attributes:
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,
];
For example the CPTs order and person are registered like this
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 );
}
However, when in the wp-admin, I currently only see persons whereas orders gets me an empty list.
Debugging this with the Debug Bar and Query Monitor, I get the following main query for order (redacted the post_status for both queries)
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
And the query for person is
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
Now I understand SQL good enough to know that this line
AND (wp_posts.ID = '0')
is the reason I don't get any results. I just don't have any idea why it is there. I don't have any pre_get_posts hook set, deactivated all plugins except this one, no change whatsoever.
-
Are you using
pre_get_posts? Note that filter is for all queries, not just frontend queries, you have to check for the main query, and you have to explicitly check for admin vs frontend, or it'll also be applied to all your admin post screens – Tom J Nowell ♦ Commented Jun 27, 2018 at 11:52 - @TomJNowell No. The installation is yet very basic: ACF (which I disabled, nothing changed) and my custom plugin. Which right now only adds the CPTs and REST endpoints (the latter I disabled, nothing changed) – kero Commented Jun 27, 2018 at 12:17
-
3
orderis in the list of CPT that you cannot use : codex.wordpress/Function_Reference/register_post_type – mmm Commented Jun 27, 2018 at 12:26 - @mmm Thanks alot! Please write it up as an answer. Why does the new docu not show vital info such as this? – kero Commented Jun 27, 2018 at 12:49
1 Answer
Reset to default 1As mmm pointed out in the comments, order should not be used as a name for a custom post type, as it may "interfere with other WordPress functions". Read more in the Codex:
Reserved Post Types The following post types are reserved and used by WordPress already.
postpageattachmentrevisionnav_menu_itemcustom_csscustomize_changesetIn addition, the following post types should not be used as they interfere with other WordPress functions.
actionauthorordertheme
本文标签: wp queryUnable to retrieve any posts of CPT in wpadmin
版权声明:本文标题:wp query - Unable to retrieve any posts of CPT in wp-admin 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749241913a2338238.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


pre_get_posts? Note that filter is for all queries, not just frontend queries, you have to check for the main query, and you have to explicitly check for admin vs frontend, or it'll also be applied to all your admin post screens – Tom J Nowell ♦ Commented Jun 27, 2018 at 11:52orderis in the list of CPT that you cannot use : codex.wordpress/Function_Reference/register_post_type – mmm Commented Jun 27, 2018 at 12:26