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 person
s whereas order
s 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 person
s whereas order
s 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.
post
page
attachment
revision
nav_menu_item
custom_css
customize_changeset
In addition, the following post types should not be used as they interfere with other WordPress functions.
action
author
order
theme
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:52order
is in the list of CPT that you cannot use : codex.wordpress/Function_Reference/register_post_type – mmm Commented Jun 27, 2018 at 12:26