WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#14823 closed defect (bug) (duplicate)

Allow get_pages to work with non-hierarchical post types

Reported by: aaroncampbell Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: dev-feedback has-patch
Focuses: Cc:

Description

I discovered this issue while working on making a custom post type a child of another custom post type. I know that's an edge case, but stay with me. I needed something like page_attributes_meta_box() but I needed to show the parent post type in the dropdown, so I rolled my own (there are no filters available for this).

My new function needed to use wp_dropdown_pages() but kept getting an empty set. It turns out it's because wp_dropdown_pages() uses get_pages(), which does a seemingly unnecessary check to make sure the post type is hierarchical. I made it work by making my post type hierarchical, but that messes up the URLs.

Attachments (1)

14823.001.diff (747 bytes) - added by aaroncampbell 4 years ago.

Download all attachments as: .zip

Change History (7)

aaroncampbell4 years ago

comment:1 scribu4 years ago

Tempted to close this as duplicate of #12821

comment:2 nacin4 years ago

  • Milestone 3.1 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

comment:3 grandslambert3 years ago

  • Cc shane@… added
  • Resolution duplicate deleted
  • Status changed from closed to reopened

Can someone explain to me why wp_dropdown_pages still does not allow non-hierarchical post types? With Custom Post Types able to be set to page compatibility and non-hierarchical, this should be a non issue. I understand why in the past page types were hierarchical and post types were not. However, things have changed and there are use cases where non-hierarchical post types with the page compatibility are going to be used, and we as plugin developers are going to need to get a dropdown of page types that are non-hierarchical.

Or perhaps a new function, wp_dropdown_posts(), should be considered. For now I guess I will have to create my own because I just have to have something that works.

comment:4 scribu3 years ago

  • Resolution set to duplicate
  • Status changed from reopened to closed

First of all, this ticket was marked as duplicate. Therefore, any question you have should be directed to the main ticket, #12821.

If you were to read #12821, you would see that it would take care of your problem.

comment:5 grandslambert3 years ago

Sorry, but I do not feel they are the same issue. I will however post future follow ups on that ticket that seems to be going nowhere to fix this problem.

comment:6 scribu3 years ago

If get_pages() is merged into get_posts(), then when wp_dropdown_pages() calls get_pages(), it will work for non-hierarchical post types too. Problem solved.

Note: See TracTickets for help on using tickets.