Create subpage – filter parent pages list

I have a website here with a lot of content and with the content where is necessary to create pages in hierarchy. But it is uncomfortable to go through the dropdown in the administration with a lot of pages. So my point is – in the admin at the moment i create/edit page and need to select the parent page from the list, I want to somehow filter or limit or search the list of possible parent pages. Thank you!

Related posts

Leave a Reply

3 comments

  1. Found a plugin but haven’t tried it: Parent Page Filter.

    The following function can show children of site-root-level pages. This is useful for many instances, but unfortunately not useful if you want to filter for children of any page that is not at site root. I don’t know PHP or WP well enough to suggest how to make this work on any page, instead of site-root-level pages.

    function fws_admin_posts_filter( $query ) {
        global $pagenow;
        if ( is_admin() && $pagenow == 'edit.php' && !empty($_GET['my_parent_pages'])) {
            $query->query_vars['post_parent'] = $_GET['my_parent_pages'];
        }
    }
    add_filter( 'parse_query', 'fws_admin_posts_filter' );
    
    function admin_page_filter_parentpages() {
        global $wpdb;
        if (isset($_GET['post_type']) && $_GET['post_type'] == 'page') {
            $sql = "SELECT ID, post_title FROM ".$wpdb->posts." WHERE post_type = 'page' AND post_parent = 0 AND post_status = 'publish' ORDER BY post_title";
            $parent_pages = $wpdb->get_results($sql, OBJECT_K);
            $select = '
                <select name="my_parent_pages">
                    <option value="">Parent Pages</option>';
            $current = isset($_GET['my_parent_pages']) ? $_GET['my_parent_pages'] : '';
            foreach ($parent_pages as $page) {
                $select .= sprintf('
                    <option value="%s"%s>%s</option>', $page->ID, $page->ID == $current ? ' selected="selected"' : '', $page->post_title);
            }
            $select .= '
                </select>';
            echo $select;
        } else {
            return;
        }
    }
    add_action( 'restrict_manage_posts', 'admin_page_filter_parentpages' );
    

    Source

    I assume this answer was first attempting to link to this page, but the link was dead. Found live link through Google.