Displaying Children of several pages

I have some code that works to display the children of a single page. I’m using this to display the children of a page in my footer.

$args = [
‘post_type’=>’page’, //this is the custom post type
‘child_of’=> ‘1452’,
];

// we get an array of posts objects
$posts = get_posts($args);

// start our string
$str = ‘<ul>’;

// then we create an option for each post

foreach($posts as $key=>$post){
$str .= ‘<li><a href=” ‘.get_permalink($post).’ “>’.$post->post_title.'</a>
</li>’;
}
$str .= ‘</ul>’;

echo $str;
}

But I want to display the children of several pages – and when I try to use several instances of the code, of course, it displays only the first ID.

I’ve tried changing this into a function – but I can’t get it to work. This is probably a very stupid question, but I’m a small-time PHP hack.

EDIT: I’ve just seen that it is not only pulling children from the page ID I have specified, it’s pulling a few from everywhere. Very strange.

Read more here:: Displaying Children of several pages

Leave a Reply

Your email address will not be published. Required fields are marked *