You’re using get_children
and it’s doing exactly what you told it to do. You told it to get all the descendants of that post, and thats what you got. You need to be more specific about what you’re querying for, that you only want immediate descendants.
You almost had the right idea originally:
$pages = get_pages(array('child_of' => $postid ));
But there is no child_of
parameter according to the WP_Query
documentation. So instead of asking for a posts children, ask for posts with a parent of $postid
, giving us:
$pages = get_posts(array(
'post_parent' => $postid,
'post_type' => 'page'
));
Other notes:
- Use a grid system or left floated divs instead of a table, it’s more flexible and you can remove your counting logic making your loop much simpler
- Indent your code, indented code is easier to read, makes an entire class of errors obvious, and makes it easier for people to understand your code and write answers to your questions
- Use
foreach () {}
rather thanforeach(): endforeach;
, it works better with editors and automated tools and checkers. - Only put 1 command per line
- All your divs have an ID of polaroid, but IDs are meant to be unique, use a class instead