0

Got this bit of code which runs which gets the Page ID and displays all the children under it. Which is good.

Part two of this is getting it to pull in the child of children items.

So currently looks like this

Main Menu Item
     Child Item
     Child Item
     Child Item

But I need it to look like this

Main Menu Item
     Child Item
          Child Item
          Child Item
          Child Item

This is the code I am using

<?php
    $args = array(
        'post_type'      => 'page',
        'posts_per_page' => -1,
        'post_parent'    => 92,
    );
    $parent = new WP_Query( $args );
    if ( $parent->have_posts() ) : ?>
        <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
            <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
        <?php endwhile; ?>

    <?php endif; wp_reset_postdata(); ?>
0

You can do what you need to with the wp_list_pages() function:

<?php
wp_list_pages(
    [
        'child_of'    => 92,
        'title_li'    => false,
        'sort_column' => 'menu_order',
    ]
);
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.