• I am trying to return 5 random pages from two page parents and cannot get it to work. My current code works fine to pull the information for a single page parent (1763) using post_parent –

    $args=array(‘post_type’ => ‘page’, ‘post_parent’ => 1763, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 5, “orderby” => ‘rand’);
    query_posts($args);

    I need it to work with multiple post_parent’s. This doesn’t work, but this gives you an idea of what I am trying to do with post_parent –

    $args=array(‘post_type’ => ‘page’, ‘post_parent’ => (1763,1764), ‘post_status’ => ‘publish’, ‘posts_per_page’ => 5, “orderby” => ‘rand’);
    query_posts($args);

    Any help would be greatly appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter henriemedia

    (@henriemedia)

    Any help on this would be great! Thank you.

    I would also like to know if there is any way of doing multiple post_parent, or any kind of work around. It would be darn useful!

    Anyone?

    There is a workaround: make the multiple parents children of one parent if they’re not already, then use that parent to list just the grandchildren, almost like a ‘post_grandparent’.

    Found this code elsewhere on the support forums, seems to work for me:

    <?php
    echo 'get pages';
    $parent = 93;
    $args=array(
      'child_of' => $parent
    );
    $pages = get_pages($args);
    if ($pages) {
      foreach($pages as $post) {
        setup_postdata($post);
        if ($post->post_parent != $parent ) { ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
          <?php
        }
      } // foreach($pages
    } // if ($pages
    ?>

    I modified the following part of the code to get the pages to come up randomly, and set the number of pages to show up:

    $args=array('child_of' => $parent, 'number' => 19); $pages = get_pages($args); shuffle($pages);

    The no. of pages output is rather weird though. If I put 12, I get 6. I put 19 as the number and I get 12 which is the number of pages I need. Weird!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Multiple post_parent's in query_posts’ is closed to new replies.