WordPress.org

Forums

get_posts() versus query_posts() confusing (2 posts)

  1. saltlakejohn
    Member
    Posted 8 years ago #

    The difference between get_posts() and query_posts() confuses me. Under what circumstances would I use one in preference to the other?

    Do both of them extract a subset of ALL posts into an array that can be passed into another Loop?

  2. dcstrad
    Member
    Posted 7 years ago #

    Do both of them extract a subset of ALL posts into an array that can be passed into another Loop?

    Yes. However, with query_posts() you don't need to use the setup_postdata() function, while with get_posts() you do. The other thing I have noticed is that after using query_posts(), the is_archive() conditional tag returns TRUE. So if you're going to use the conditional tags (is_single(), is_page(), is_archive(), etc.), do not use query_posts().

Topic Closed

This topic has been closed to new replies.

About this Topic