Hierarchical custom post types – multiple post_name not queried correctly
-
I have registered a custom post type with settings ‘hierarchical’ => true and ‘supports’ => array(‘title’, ‘editor’, ‘page-attributes’)
The intention is to use this post type for hierarchical posts much like the “page” post type.
I have two posts with the following data:
“Post 1”
post_name: post-slug-here
url: /custom-post-type/post-slug-here/“Post 2”
post_name: post-slug-here
url: /custom-post-type/parent-slug/post-slug-here/When I visit the URL /custom-post-type/post-slug-here/ you expect to see “Post 1”, however it is actually “Post 2” being served up by WordPress.
A quick dump of $wp_query shows that WordPress has found both “Post 1” and “Post 2” in its request, however it has incorrectly decided to use “Post 2” for the $post variable.
The request should really order by post_parent ASC, this way always prioritising the post with post_parent = 0 over a subpage
- The topic ‘Hierarchical custom post types – multiple post_name not queried correctly’ is closed to new replies.