• Resolved ripsup

    (@ripsup)


    Was attempting to run a seperate query and then query_posts on it.

    $my_query = new WP_Query();
    $my_query->query_posts(‘meta_key=rotation_enabled&meta_value=on’);

    But I am receiving this error.

    Fatal error: Call to undefined method WP_Query::query_posts()

    If I switch the line to
    $my_query->query_posts(‘meta_key=rotation_enabled&meta_value=on’);

    This works fine. All documentation that I have found points to the first example working. I am doing this in the header if that changes things but what am I missing?

    Thanks,
    Richard

Viewing 1 replies (of 1 total)
  • Thread Starter ripsup

    (@ripsup)

    Okay found something that finally explained the issue.

    https://codex.www.ads-software.com/Template_Tags/query_posts

    The query_posts function is intended to be used to modify the main page Loop only. It is not intended as a means to create secondary Loops on the page. If you want to create separate Loops outside of the main one, you should create separate WP_Query objects and use those instead. Use of query_posts on Loops other than the main one can result in your main Loop becoming incorrect and possibly displaying things that you were not expecting.

Viewing 1 replies (of 1 total)
  • The topic ‘query_posts issue’ is closed to new replies.