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.

Can anyone please help me to with the wp_query.

I am making a template file/loop to create and archive page of the current page children pages.

This query needs to be automatic as I am using in on few pages.

This is my query below, but it just returns my posts instead of child pages.

<?php

$parent = new WP_Query(array(

    'post_parent'       => $post->ID,                               
    'order'             => 'ASC',
    'orderby'           => 'menu_order',
    'posts_per_page'    => -1

));

if ($parent->have_posts()) : ?>

    <?php while ($parent->have_posts()) : $parent->the_post(); ?>

        <div id="parent-<?php the_ID(); ?>" class="parent-page">                                

            <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>

            <p><?php the_advanced_excerpt(); ?></p>

        </div>  

    <?php endwhile; ?>

<?php unset($parent); endif; wp_reset_query(); ?>

Thanks in advance for any help.

Josh

share|improve this question
    
Try this solution == get children of a post - wordpress.stackexchange.com/a/123143/42702 –  taztodgmail Nov 13 '13 at 10:36
add comment

1 Answer

up vote 4 down vote accepted

You have to change child_of to post_parent and also add post_type => 'page':

WordPress codex Wp_query Post & Page Parameters

<?php

$args = array(
    'post_type'      => 'page',
    'posts_per_page' => -1,
    'post_parent'    => $post->ID,
    'order'          => 'ASC',
    'orderby'        => 'menu_order'
 );


$parent = new WP_Query( $args );

if ( $parent->have_posts() ) : ?>

    <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>

        <div id="parent-<?php the_ID(); ?>" class="parent-page">

            <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>

            <p><?php the_advanced_excerpt(); ?></p>

        </div>

    <?php endwhile; ?>

<?php endif; wp_reset_query(); ?>
share|improve this answer
    
Thanks dude, I tried post_parent original but it's 'post_type' => 'page' that is the key - does wordpress querys default to post then? I will accept answer when it lets me. –  Joshc Jul 31 '12 at 9:27
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.