WordPress.org

Ready to get started?Download WordPress

Forums

Problem with query posts (2 posts)

  1. needle189
    Member
    Posted 5 years ago #

    Hi people I am having a little bit of a problem with understanding query posts. In the documentation of query posts in wordpress codex

    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.
    The query_posts function overrides and replaces the main query for the page. To save your sanity, do not use it for any other purpose.

    I didn't understand the part of 'modifying main page loop only'.So query posts can't be used in the sidebar or footer to display the recent posts or comments or featured posts ?

  2. MichaelH
    Member
    Posted 5 years ago #

    Using the template tag, get_posts(), or a new WP_Query, is a better choice.

Topic Closed

This topic has been closed to new replies.

About this Topic