Support » Fixing WordPress » new WP_Query works and query_posts does not

  • Dvvarf

    (@dvvarf)


    I’m on the brink of questioning my own sanity with this one.
    So I’ve got this query_posts call used in one of my templates:

    query_posts(array(
    	'post_type' => 'some-post-type'
    ));

    Somewhere around a week ago it suddenly stopped working (no changes to the codebase).
    Replaced it with this:

    $wp_query = new WP_Query(array(
    	'post_type' => 'some-post-type'
    ));

    And everything works.
    $wp_query objects created are identical in both cases but in first case have_posts returns nothing and in second one returns true. On the very same page query_posts with another post_type works, but not with the one I need.
    What could be the problem here? There should be no difference between these calls or am I missing something?
    P.S. Calling directly $wp_query->query($args) also returns nothing.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    Dvvarf

    (@dvvarf)

    The thing is there is not much code besides that, if you leave only something like that in page code:

    query_posts(array(
    	'post_type' => 'some-post-type'
    ));
    if(have_posts()) {
    echo 'have posts';
    } else {
    echo 'nothing here';
    }

    Then it works exactly the same. The difference is all between calling WP_Query or the same new WP_Query, but through query_posts function. No functions modifying query, no plugins (except adding custom post-type of course), nothing…
    While using pre_get_posts would make thing look a bit more neat, merging a lot of completely different loops in one function will not make things much better.
    By the way, plugin and custom type in question – http://wordpress.org/plugins/external-videos/, but I didn’t update it in a while (still version 0.14).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘new WP_Query works and query_posts does not’ is closed to new replies.