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
- When to use WP_query(), query_posts() and pre_get_posts
- posts_per_page no limit
- Get post ids from WP_Query?
- Nested meta_query with multiple relation keys
- How do I exclude a custom taxonomy from the post loop
- Some doubts about how the main query and the custom query works in this custom theme?
- Why query_posts() isn’t marked as deprecated?
- Alternative to query_posts for main loop? [duplicate]
- Wp get all the sub pages of the parent using wp query
- how to query posts by category and tag?
- How to get post content by calling ajax?
- Using WP_Query to Query Multiple Categories with Limited Posts Per Category?
- Get the ID of the latest post
- How to query for most viewed posts and show top 5
- Order by meta value or date?
- How do I query by post format in WordPress 3.1
- Display posts of the last 7 days
- How to show related posts by category
- Query Posts or Get Posts by custom fields, possible?
- WP Query where title begins with a specific letter
- Is there a way to exclude the content from the post variable to save on RAM usage?
- Filtering posts by post meta data
- How to use the_posts_navigation for wp_query and get_posts?
- Querying posts from multiple sites in a network?
- How to query_posts using meta_query to orderby meta_key AND have a secondary sort by date?
- Query posts by custom taxonomy ID
- meta_query: using BETWEEN with floats and/or casting to DECIMAL
- Display/query post formats
- Get posts from Network (Multisite)
- How to order by post_status?
- Using get_posts vs. WP_Query
- How to query post by user role?
- Delete all posts from WordPress except latest X posts
- Using WordPress to make a “Product Search” type navigation drilldown