WordPress.org

Make WordPress Core

Opened 3 weeks ago

Last modified 3 weeks ago

#49623 new defect (bug)

Hierarchical Custom Post Types do not show up in the REST API

Reported by: alanford123 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: reporter-feedback
Focuses: rest-api Cc:

Description

When querying custom post types that are hierarchical, every non-parent item does not get returned.

To reproduce:

Create a custom post type, with

'hierarchical' => true,

Add some items, and set some to be child items.

Try to get a list of all the items using REST API, as such:

?rest_route=/wp/v2/-custom-post-type-

Observe that not all items get returned. All that are child items do not get returned.

It may have something to do with the url structure. Pages work as expected, and pages have all items with the same URL structure,

?page_id=1

Regardless of being child or not.

Custom post types have a different url structure, where the items dont actually have id as their URL, but their slug.

CHild items have "parent-slug/child-slug"

Change History (2)

#1 @alanford123
3 weeks ago

Short update:

I observe the same behavior from the get_posts() function

#2 @TimothyBlynJacobs
3 weeks ago

  • Focuses javascript removed
  • Keywords reporter-feedback added; needs-patch removed
  • Version changed from 5.3.2 to 4.7

Hi @alanford123!

Welcome to trac and thanks for your ticket!

Could you try this with all plugins disabled and a stock WordPress theme? We have automated tests to verify that all posts are returned, including child posts, when doing a regular request to a hierarchical post type.

Note: See TracTickets for help on using tickets.