Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress admin: show draft pages in page attributes parent page dropdown

Tags:

wordpress

For clarity - here is a picture of the box I am talking about in this question: Screenshot of post parent dropdown list

Background: I have built a relatively complex WP site for a client which is more of a CMS than a blog and relies on a hierarchy of pages being built. (Well, they're actually custom post types with 'hierarchical' => true set)

My question: is it possible to show draft (or pending review) pages in the page attributes 'Parent page' dropdown list? Without this, it means making each page live before the whole section is ready - and that's not a suitable solution.

What I've tried:

  • Looking for an action which gets called to build the list (can't find one)
  • Looking in the source code for where the list is created (it's built with wp_dropdown_pages which doesn't appear to let you choose the post status)
  • Looking for plugins which provide this functionality
like image 328
iblamefish Avatar asked Aug 21 '10 17:08

iblamefish


People also ask

Are WordPress draft pages visible?

Saving a page as a draft lets you have a page set up and ready, but it isn't viewable to the public yet. This means you can create the page, edit it how you want, or even completely mess up the page, and nobody would even know. Drafts are only visible if you are logged into your website to make edits.

What is Page Page parent attributes?

A parent page is a top-level page, with child pages nested under it. Parent page drop down in Page Settings. For example, you could have an “About” page as a top level or parent page, and then have child pages “Life Story” and “My Dogs” under it.

How do I change the parent page in WordPress?

On your WordPress dashboard, go to Pages -> Add New. Enter the desired title and content. Open the Page tab and scroll down to Page Attributes. Choose a specific page to set as the parent from the drop-down menu.


1 Answers

Very nice question!

The following does it. One filter is for the edit page screen and the other for the Quick Edit menu.
Tested with a hierarchical custom post type.

add_filter( 'page_attributes_dropdown_pages_args', 'so_3538267_enable_drafts_parents' );
add_filter( 'quick_edit_dropdown_pages_args', 'so_3538267_enable_drafts_parents' );

function so_3538267_enable_drafts_parents( $args )
{
    $args['post_status'] = 'draft,publish,pending';
    return $args;
}

drafts enabled as parents

like image 162
brasofilo Avatar answered Sep 26 '22 18:09

brasofilo