What other alternatives are there to WordPress query_posts()?

The WordPress codex says that:

query_posts() is only one way amongst many to query the database and generate a list of posts. Before deciding to use query_posts(), be sure to understand the drawbacks.

Read More

but it does not list what those alternatives to query_posts() are. Should I be using something else?

Related posts

Leave a Reply

3 comments

  1. You could use get_posts() or create a new WP_Query. There are a few more too that are a little more specific such as wp_get_recent_posts(). Have a look through wp-includes/post.php to see some of the available ways to get posts. I can’t tell you if you should be using something else without knowing what you are trying to do.

  2. query_posts will update the global $wp_query. Maybe you don’t want that.

    If you do $my_query = new WP_Query and then $my_query->query_posts you won’t mess with the globals.

    Sometimes it’s easier to use get_posts()

    Also you have the option to make your own sql requests.