• 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)
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.