• Resolved implemagician

    (@implemagician)


    I’ve used the code below to make private pages show up in the Appearance->Menu screen so the user can add private pages to a menu. Which recently just stopped working, only public pages are showing up in the Page options to add to the menu.

    1. There are no error in our error log, even with WP Debugging turned on.
    2. I can put an echo ‘here’ in it and I can see that it is getting called.
    3. I’m using a child theme of Twenty Fifteen

    /**
    * Add query argument for selecting pages to add to a menu
    */
    function steele_show_private_pages_menu_selection( $args ){
        if( $args->name == 'page' ) {
            $args->_default_query['post_status'] = array('publish','private');
        }
        return $args;
    }
    add_filter( 'nav_menu_meta_box_object', 'steele_show_private_pages_menu_selection' );

    Did something change when updating to 6.0 and navigation blocks? The site is still using Appearance->Menu for menus.

    WP Version – 6.0.1
    Server architecture – Linux 5.10.0-16-amd64 x86_64
    Web server – Apache
    PHP version – 7.4.30 (Supports 64bit values)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Interesting question. I’ve never thought of that before. I just looked at the source code and the solution is pretty simple: set a higher priority for the filter:

    add_filter( 'nav_menu_meta_box_object', 'steele_show_private_pages_menu_selection', 9999 );

    After that it works as desired. The reason might be that there are several WordPress-specific filter uses of nav_menu_meta_box_object. They change the WP_Query specifications so that this adjustment no longer works. With a higher priority, your function runs after all the others, making the post_status customization work.

    Thread Starter implemagician

    (@implemagician)

    That fixed the issue. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Code to Show Private Pages on Menu Screen Not Working’ is closed to new replies.