Hi @janoChen:
If you have a choice, go with WP_Query
. Both of the other functions (query_posts()
and get_posts()
) call WP_Query
indirectly.
The former is designed to allow you to modify the main query after the standard query has already been run, for example when you want a second loop. But query_posts()
affects global variables and can have side-effects. If possible use WP_Query instead and your code will be more robust.
As for get_posts()
, it’s just a wrapper around WP_Query
with some potentially unexpected defaults so you might as well call WP_Query
directly and avoid those issues.
Related Posts:
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- How to Get All Posts with any post status?
- How can i get count from query post
- query_post by title?
- WP_Query vs get_posts
- How to return results of a get_posts() in explicitly defined order
- How to set posts per page using WP_Query()
- query_posts() in function makes global $wp_query out of sync?
- Problem with ‘post__not_in’
- Get posts by meta data OR title
- Sort posts alphabetically by custom field value, insert divider between different letters
- Custom Post Type “Event”: chronological list of recurring events
- How to get previous 10 days post from a specific date – WP Query
- Meta Query with date and time on the same Day before given time
- Retrieving 3 latest post from each of 5 different custom post types
- Total Count of Posts NOT in Selected Categories?
- how could I get the pagination as I want to when query posts using get_posts function
- how to display active, upcoming and past event with featured listing with pagination
- How to find out what “Blog pages show at most” is set to [duplicate]
- Post count per (day/month/year) since blog began
- Quickest way to get last or oldest post date – WP Query
- How to get 4 Posts after the 5 most recent ones
- How do you Query posts with nothing in common?
- making random query button using $_GET
- Order posts using a custom array
- how to exclude “featured” posts from the main loop?
- Tricky WP Query
- WordPress pagination showing same posts on each page
- Show Only Posts Owned By Logged In User + my post
- Search breaks when querying main loop for category
- WordPress pagination with get_posts?
- Using ajax with paging and a custom sub-query
- add active class based on permalink and url
- My post repeats itself on the second page [closed]
- Custom loops, sticky posts, and pagination nightmare
- Reset WordPress Post Query to default
- get_the_title outputs title until spacing; it does not get full length of title
- Get all posts which was posted on X Days WordPress
- get_posts output always same post
- Use WP_Query or query_posts() or get_posts() for optimizing a site?
- complex get_posts() query to select child pages
- How to give classname to post if post has no content?
- Posts query according to meta box date
- WordPress query reverse order
- Multiple posts/pages in one page?
- Posts being viewed
- How to query for a page, get data, then query for child pages of that page
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- Querying a query
- odd behaviours from template tags
- Having an issue doing a WP_Query with post_content and category__and
- Custom query looking at multiple custom fields and properly sorting
- Pre-existing arguments when using queries
- search.php to search only the post title
- Facing problem with tax_query results
- allow user to edit posts made by others users based on the user role
- Create a hierarchical loop at predefined markup requirements
- Ordering Posts by parent category, name ascending
- When should you use WP_Query vs query_posts() vs get_posts()?
- Post per page not working
- How to refine WP-Query with further criteria
- Run second query on page based on author of the first query
- Query Posts (post meta)
- How do I correctly query posts from a post ID?
- query_posts works while get_posts doesn’t
- Query Posts in a Predefined Order
- Custom Taxonomy not working with posts_per_page in new WP_query (pagination problem)
- Modify main WordPress loop with a parse_query filter
- Display Posts by modifying the where clause only for my query
- Use union/intersection query_posts variables in uri request parameter form?
- query_posts doesn’t order by title
- How to query ‘posts_per_page’ to display a different blog posts index template?
- Trying to check and see if a post has a featured image outside of the main loop
- Dynamically excluding current page id
- How do i paginate query_posts with numeric pagination?
- How can I pick a single post from the latest 3?
- Get posts for last working week in WP_Query
- Sorting multiple custom post types without a meta key/value pair by sort order
- Logged in user ID as post ID
- Custom Query num_rows returns wrong amount
- Fetch Record based on meta key dates
- Stuck in Order by more then one
- ACF Query meta_values don’t work with ‘offset’
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- Why does get_posts only show results for Admins or logged-out users?
- define orderby URL with meta_key=post_views_count
- How to query the latest 5 posts and sort them by title?
- Advanced WP Query and/or
- how to store wordpress loop in array?
- Frontend form with multiple posts
- Way to cache a query for 24 hrs
- WordPress query portfolio posts
- Remove Post if Advanced Custom Field is checked to fix paging
- Display 3 posts with different HTML markup using a loop
- Query only title/field/featured media of posts [closed]
- Remove duplicated posts in the loop if post has more than one category
- query_posts not working after wordpress 3.7 update
- Is that the query_posts() the real criminal here?
- Lots of SQL queries