Title: BUG? WP_Query() does not return the same result as query_posts()
Last modified: August 21, 2016

---

# BUG? WP_Query() does not return the same result as query_posts()

 *  [danielkun](https://wordpress.org/support/users/danielkun/)
 * (@danielkun)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/bug-wp_query-does-not-return-the-same-result-as-query_posts/)
 * Hello!
 * I’m running WordPress 3.8.1 and I’m having problems using a custom WP_Query().
 * I’m using an array with these arguments:
 *     ```
       $args = array(
         'tag_slug__and' => array('usa', 'china'),
         'category__and' => array(211, 420),
         'posts_per_page' => '-1',
         's' => 'money',
       );
       ```
   
 * **The following code works:**
 *     ```
       $GLOBALS['wp_query'] = new WP_Query();
       return $GLOBALS['wp_query']->query($args);
       ```
   
 * **Whereas this does not work:**
 *     ```
       $obj = new WP_Query();
       $posts = $obj->query($args);
       return $posts;
       ```
   
 * I var_dumped each object and they look exactly the same, except for one difference–
   the first one contains has a post in the “posts” array whereas the second one
   is empty.
 * The first code above is taken straight out of query_posts().
 * Do I have to use $GLOBALS to get this to work?
 * **I should add that the “s” key plays a major role. If I remove the row that 
   contains the search string, the second code snip works as well.**
 * This feels like a WP bug..

Viewing 1 replies (of 1 total)

 *  Thread Starter [danielkun](https://wordpress.org/support/users/danielkun/)
 * (@danielkun)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/bug-wp_query-does-not-return-the-same-result-as-query_posts/#post-4946264)
 * get_posts() seems to do the job correct as described [here](http://codex.wordpress.org/Function_Reference/get_posts).

Viewing 1 replies (of 1 total)

The topic ‘BUG? WP_Query() does not return the same result as query_posts()’ is 
closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [danielkun](https://wordpress.org/support/users/danielkun/)
 * Last activity: [11 years, 12 months ago](https://wordpress.org/support/topic/bug-wp_query-does-not-return-the-same-result-as-query_posts/#post-4946264)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
