Excluding child categories, but not their grandchildren
-
I’m trying to list the grandchild pages of a page, but not it’s direct children. In this example, the page whose grandchildren I am trying to get is “Portfolio”. There are three different pages within Portfolio (for different types of media), and then about 3 within each of those (portfolio items to show).
I want all of the portfolio items to show at once, but I don’t want their parent pages (the types of media) to show up in there as if they were portfolio items themselves. I’ve tried to set a custom value to the pages I want to show up, but these don’t show up unless their respective parent page also has the same custom value.
Is there anyway to exclude the child pages, but not the grandchild pages within? Anyways, here is my code. Any help is appreciated.
<?php $parentID = 20; $args = array( 'child_of' => $parentID, 'meta_key' => "splash", 'meta_value' => "true" ); $pages = get_pages($args); foreach($pages as $child) { $portname = get_the_title($child->ID); $portlink = get_permalink($child->ID); ?> <h3><a href="<?php echo $portlink; ?>"><?php echo $portname; ?> / <span class="category"><?php echo $portcat; ?></span> </a></h3> <?php } ?>
- The topic ‘Excluding child categories, but not their grandchildren’ is closed to new replies.