Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

spindogs on "Hierarchical custom post types - multiple post_name not queried correctly"

$
0
0

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


Viewing all articles
Browse latest Browse all 8245

Trending Articles