• Resolved querkmachine

    (@querkmachine)


    I used the example code on the get_page_children function reference to display child pages within a custom page template. This worked fine while the site was on my development server, but as soon as it went live it stopped working.

    $my_wp_query = new WP_Query();
    $all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
    $portfolio =  get_page_by_path('portfolio');
    $pch = get_page_children($portfolio->ID, $all_wp_pages);

    The problem appears to be the second line, it’s not grabbing all the pages in the database (yes, they are there), instead it’s only getting the newest page.

    Being a bit of a newbie at using WordPress, I’m a little bit stumped as to what to do. How can this be fixed, or is there some other code snippet I can use to get the children of a page returned as objects?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter querkmachine

    (@querkmachine)

    I take it that people are as clueless as I, then?

    you might need to add the ‘posts_per_page’ parameter, with -1 for all pages, to your query:

    $all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'posts_per_page' => -1));

    Thread Starter querkmachine

    (@querkmachine)

    That sorted it, I completely forgot I had the setting to only show one post per page! Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Code to list child pages not working’ is closed to new replies.