• I’m trying to query pages from more than one parent page. This is the code I’m currently using which doesn’t work.

    <?php $my_query = new WP_Query ('static=true&post_parent=7,8,9&post_status=publish&order=DESC'); ?>
    <?php if ($my_query->have_posts()) : ?>
    <?php $count = 0; ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <?php $count++; ?>
    <div id="latest">Latest</div>
    <div><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></div>
    <?php the_excerpt(); ?>
    <?php if( $count <= 1 ) break; ?>
    <?php endwhile; endif; ?>

    Any ideas? Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Just a guess but try post_parent=array(7,8,9). And I’m not sure what static=true is for. Perhaps you meant post_type=page?

    I don’t believe you can use arrays in a query string, you’d need to convert the whole set of args to an array to try that out.

    eg.

    array( 'static' => true, 'post_parent' => array( 7, 8, 9 ), 'post_status' => publish', 'order' => 'DESC' )

    Thread Starter thisisedie

    (@thisisedie)

    Thank you esmi but that didn’t work either. As for static=true, I was using that because post_type=page has never worked for me before. Wouldn’t display anything unless I used static=true. I tried it just now again though and it works. Only difference is I’m using WP 3. Hmmm.

    Thread Starter thisisedie

    (@thisisedie)

    Thanks to you too t31os but that doesn’t work either. Everything I try just gives me the last page published no matter what the parent is.

    Thread Starter thisisedie

    (@thisisedie)

    Ok, how about this. Can anyone tell me how I’d exclude a page and it’s children when using the original code I posted?

    query_posts and get_posts using post_parent as far as the docs say only support a single value, not several.

    Perhaps something here might help.
    http://codex.wordpress.org/Function_Reference/get_page_children

    If not, then you might just have to fetch more pages then you need and skip over any that are children of particular pages.

    get_pages has an exclude tree parameter, but i do remember there being a bug with that parameter (whether it now works i don’t know).
    http://codex.wordpress.org/Function_Reference/get_pages

    You can pick my brain if you get stuck.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Query Pages From More Than One Parent’ is closed to new replies.