I have a page ("testimonials"). It has 3 subpages ("children") : "press", "people", "enterprises".
Each of the subpages have their own subpages (grandchildren of "Testimonials"), which are the actual testimonials files.
I would like to display on my frontpage the most recent grandchild page. How can i do that?
I tried using get_pages() like this:
$myposts = get_pages('number=1&child_of=28&sort_column=post_date&sort_order=desc&parent=');
But no luck: it either displays a child or nothing.
Your help would be much appreciated.
Well, it turns out the only way i could make it work was doing a specific query in the database.
Here is the query, and the generated loop if anyone is having the same need.
$querystr = "SELECT p3.*
FROM $wpdb->posts p1
LEFT OUTER JOIN $wpdb->posts p2 ON p2.post_parent=p1.ID
LEFT OUTER JOIN $wpdb->posts p3 ON p3.post_parent=p2.ID
WHERE (p1.post_status = 'publish' AND p1.post_type = 'page' AND p1.ID ='28') AND (p3.post_status = 'publish' AND p3.post_type = 'page') ORDER BY p3.post_date DESC LIMIT 0,1";
$myposts = $wpdb->get_results($querystr, OBJECT);
if ($myposts) {
foreach($myposts as $post) :
setup_postdata($post);
$postimageurl = get_post_meta($post->ID, 'post-img', true);
$postimageurl = ($postimageurl) ? $postimageurl : '/medias/img/temoignage-banner.jpg';
?>
<div id="importantBanner" style="background-image:url(<?php bloginfo('url');
echo $postimageurl; ?>);margin:0;padding:0;">
<a style="border-width:0" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>" id="temoignageLink">
<span class="tradeGothic" style="display:block;padding:7px 0 0 20px;font-size:12pt"><?php the_title(); ?></span>
</a>
</div>
<?php endforeach; ?>
<? }
?>