WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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
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);

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()) {
  var_dump($post); // raw dump of your child post
share|improve this answer

Your Answer


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.