Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
Please, add research efforts to your Question. Search the Codex for is_page, get_post and get_posts. –  brasofilo Jan 25 '13 at 15:58
add comment

1 Answer

up vote 0 down vote accepted

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
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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