php – Populate dropdown with Child Pages based on Parent Page chosen

Question

I’m trying to populate the Child Page dropdown with that of the selected Parent Page – If a specific Parent page is chosen it should fill the second dropdown with all Child pages listed under that parent.

Once the submit button is clicked, it would then direct users to the selected child page.

In the first dropdown, I’ve pulled the necessary Parent pages based on their page ids. I’m stuck from here. What do I do to achieve getting the secondary dropdown 100% working?

<div id="pages">
    <h2><?php _e('pages:'); ?></h2>
    <form action="<?php bloginfo('url'); ?>" method="get">

        <!-- Parent Page dropdown -->
        <?php wp_dropdown_pages( array(
          'include' => array( 119, 467, 857, 1027, 404 ), // Array of Parent Page IDs to include.
        ) ); ?>

        <!-- Child Page dropdown -->
        <?php wp_dropdown_pages( array(
          'include' => array( ), // Array based on selected Parent Page.
        ) ); ?>

    <input type="submit" name="submit" value="view" />
    </form>
</div>

0
ZUH. 4 months 2022-04-07T02:35:35-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse