• Resolved mroulston

    (@mroulston)


    I have a WordPress site with hundreds of pages, and I am trying to figure out the best way to minimize the number of pages that show up in the page attributes parent dropdown menu (I only need that menu to be 2 or 3 levels deep, depending on the parent page).

    I searched online and found the following code:

    // LIMIT PARENT DROPDOWN MENU TO TWO LEVELS
    function limit_parent_dropdown_menu( $args ){
        $args['depth'] = '2';
        return $args;
    }
    add_filter( 'page_attributes_dropdown_pages_args', 'limit_parent_dropdown_menu' );
    add_filter( 'quick_edit_dropdown_pages_args', 'limit_parent_dropdown_menu' );

    That code works almost perfectly for me, but it ends up hiding some pages that I need to see, or showing some pages that I’d rather be hidden (depending on what number I set the depth to).

    Ideally I would like to have the ability to hide most pages that are 3 levels deep, but show some level 3 pages depending on the parent.

    What I am trying to figure out is if there is a way to modify that code to use an if statement to set the depth to display 3 levels for a few certain parent pages that I specify, and 2 levels for everything else.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Use is_page() to add to your array before you limit ?
    https://developer.www.ads-software.com/reference/functions/is_page/

    Moderator bcworkz

    (@bcworkz)

    If I understand your goal correctly, it could be accomplished by using the “wp_dropdown_pages” filter to strip out unneeded page options, but it’s a crude, hacky approach. Ideally you’d have a custom walker to generate the list, but it appears the only way to do that is to develop your own meta box and use it in lieu of the default box.

    Try passing an “exclude_tree” argument that lists the IDs of undesired pages as an array. While it’s not part of the documented args for wp_dropdown_pages(), it should still get passed on to get_pages() that’s called within the function.(unverified) Just hardcode a few IDs first as a proof of concept. You can query for the needed IDs if that checks out, or just add more hardcoded IDs if that’s acceptable to you.

    Thread Starter mroulston

    (@mroulston)

    Thanks @corrinarusso and @bcworkz for responding and helping me out.

    I will try your suggestions and hopefully get this working.

    • This reply was modified 4 years, 8 months ago by mroulston.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Multiple depth settings for page attributes parent dropdown menu’ is closed to new replies.