0

What I would like to do is to create a WP loop that will display info from a child page of an adult page ID, so the Page ID is 2. I would like to pick a page ID to display what page.

So that way I could display information from another child page on an alternative page.

Owen

1
  • Please, add research efforts to your Question. Search the Codex for is_page, get_post and get_posts.
    – brasofilo
    Commented Jan 25, 2013 at 15:58

1 Answer 1

0

This is a near duplicate of a number of questions here, but the "single random result" might make it somewhat distinct.

$args = array(
    'post_type'         => 'page',
    'post_parent'       => $post->ID,                               
    'orderby'           => 'rand',
    'posts_per_page'    => 1,
    'no_found_rows'     => true
);
$child = new WP_Query($args);
var_dump($child->posts);

You are telling WP_Query to pick 1) pages, 2) with the parent of the current page, 3) ordered randomly, 4) one result, and 5) don't bother tracking found rows since we already know it should be 0 or 1.

There are numerous examples of creating multiple loops here and in the Codex. You should be able to find plenty of information to flesh this out. In short you want:

while ($child->have_posts()) {
  $child->the_post();
  var_dump($post); // raw dump of your child post
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.