• Hi all,

    I’ve got a weird problem with using the query_posts() vs. get_posts() core functions. The thing is that the query_posts() function gives me the desired children of the ID. Like:

    query_posts(array(
    'post_type' => 'page',
    'post_parent' => $optID
    ));

    But…the “post_parent” parameter shouldn’t be an optional argument for the query_posts() function… (At least not according to the documentation.)

    While the get_posts() with the same arguments returns an empty ‘query’.

    get_posts(array(
    'post_type' => 'page',
    'post_parent' => $optID
    ));

    Can anyone tell me what’s going on…?
    Thanks for your reply!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Quoting apljdi “query_posts() is meant to modify the main loop for the page, not for creating secondary loops”

    I have a parent page with two children. Those two children are both returned by the new WP_Query and get_posts:

    <?php
    $args = array(
    'showposts'=>-1,
    'caller_get_posts'=>1,
    'post_type' => 'page',
    'post_parent' => 93
    );
    $parent = new WP_Query($args);
    $parent2 = get_posts($args);
    
    echo "<pre>"; print_r($parent); echo "</pre>";
    echo "<pre>"; print_r($parent2); echo "</pre>";
    ?>

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    “post_parent” is perfectly valid. Just not documented very well.

    I’m not sure why they’d give you different results though. There’s not a lot of difference between them. get_posts suppresses filters on the query, and ignores sticky posts. That’s about it, really.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘query_posts() vs. get_posts() problem…’ is closed to new replies.