Hi,
this already took me more than six hours, but I'll give it a shot. I wanna display the content of page childs and grandchildren that have a meta_key set. This works really fine, but the problem is, that the script only displays the grandchild, when the child has set the meta_key as well. Otherwise is just won't show up.
What I need: a loop that searches all subpages (childs|grandchildren) by a meta_key no matter what the child of a grandchild has set as a meta_key.
Here is my code:
<?php
// This code displays all small teasers (overview_teaser|small)
// with all the childs and grandchildren
$mypages = get_pages( array( 'child_of' => $post->ID,
'sort_column' => 'post_date',
'sort_order' => 'desc',
'meta_key' => 'overview_teaser',
'meta_value' => 'small') );
foreach( $mypages as $page ) :
$content = $page->post_content;
$excerpt = get_post_meta($page->ID, 'page-excerpt', $single = true);
$alter_title = get_post_meta($page->ID, 'alter-title', $single = true);
$alter_link_title = get_post_meta($page->ID, 'alter-link-title', $single = true);
$thumbnail = get_the_post_thumbnail($page->ID, 'teaser-excerpt', $single = true);
?>
<article class="pod-teaser-excerpt col-4">
<figure class="thumbnail">
<?php if ($thumbnail) : ?>
<a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo get_the_post_thumbnail($page->ID, 'teaser-excerpt'); ?></a>
<?php endif; ?>
</figure>
<div class="content">
<?php if ($alter_title) : ?>
<h2 class="title"><a href="<?php echo get_page_link( $page->ID ); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php echo $alter_title; ?></a></h2>
<?php else: ?>
<h2 class="title"><a href="<?php echo get_page_link( $page->ID ); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php echo $page->post_title; ?></a></h2>
<?php endif; ?>
<div class="entry">
<?php echo $excerpt; ?>
</div>
<footer class="footer">
<a href="<?php echo get_page_link( $page->ID ); ?>" class="more-link">
more
</a>
</footer>
</div>
</article>
<?php endforeach; ?>
Right now just 5 items show up, because the missing item doesn't have a child with the meta_key set. I'm getting nuts ...
Thanks for your help!