Title: query_posts() vs. get_posts() problem&#8230;
Last modified: August 19, 2016

---

# query_posts() vs. get_posts() problem…

 *  [indigodragon](https://wordpress.org/support/users/indigodragon/)
 * (@indigodragon)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/query_posts-vs-get_posts-problem/)
 * 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)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/query_posts-vs-get_posts-problem/#post-1196222)
 * Quoting apljdi [“query_posts() is meant to modify the main loop for the page, not for creating secondary loops”](http://wordpress.org/support/topic/305809?replies=7#post-1193617)
 * 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)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [16 years, 9 months ago](https://wordpress.org/support/topic/query_posts-vs-get_posts-problem/#post-1196299)
 * “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.

## Tags

 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/query_posts-vs-get_posts-problem/#post-1196299)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
