I realise WordPress questions are hard to answer, given the plethora of plugins and complications out there.

We’ve been having some trouble on our WordPress page where virtual pages will populate their submenu with all the pages that don’t have an explicit parent(Parent: (no parent)).

I’ve isolated the offending code to this piece of code in the header:

<!-- Secondary Nav -->
<!-- Show Secondary Menu if the page is a child or has children -->
<?php global $post; $children = get_pages( array( 'child_of' => $post->ID ) );

    if ( is_page() && $post->post_parent  || count( $children ) > 0 ) : ?>

        <div class="row subnav">
            <div class="container">
                <div class="columns large-12">
                    <ul>
                        <?php wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>get_post_top_ancestor_id()) ); ?>
                    </ul>
                </div>
            </div>
        </div>

    <?php else : ?>
    <!--This is a parent page without children -->

    <?php endif; ?>

Clearly virtual pages trigger as a page with children, as opposed to a page without children. By why?

How does WordPress handle virtual pages with regards to page… childing? This bahaves as expected on normal pages, it gets a list of affiliated menu items.

I’ve seen the same behaviour on buddypress, and this is currently happening with coursepress.

Read more here: Why does this php code cause virtual pages submenus to list all parentless pages? WordPress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: