get_posts()
simply uses a WPQuery
object and sets a few default values. In general the values it sets make it mildly more performant. But I wouldn’t worry to much about it.
get_posts()
is simplier so as a rule of thumb if you don’t need any of the more involved features of WP_Query
(including pagination) – then stick with it. But largely comes down to personal preference.
I would leave your example as is. Though you don’t need to explicitly set all the values as `get_posts’ sets some by default.
Related Posts:
- Can I force WP_Query to return no results?
- meta_query ‘compare’ => ‘IN’ not working
- Use the page slug in a WP_Query?
- Sorting: custom query with orderby meta_value_num THEN by title
- WP_Query and next_posts_link
- paginate_links() adds empty href to first page and previous link
- Using OR conditions in meta_query for query_posts argument
- Get posts by menu ID
- count posts from custom taxonomy terms by year
- replace the WP_Query class in the main query
- How to grab metabox value in wp_query meta_query key
- Woocommerce query by price range and custom meta key
- Get posts with condition on comment meta value
- WP_Query sort by comment meta data
- Stop all SQL_CALC_FOUND_ROWS wordpress queries
- Move posts to top of WP_Query if in certain Taxonomy?
- WP_query ‘orderby=none’ Problem
- How can I create a WP_Query that returns posts where one meta_value
- ‘paged’ in wp_query doesn’t work
- Sorting meta_value as integer doesn’t work
- Display different number of posts from one category on the different pages
- How to display child posts in the parent category
- Get posts from the Main site to sub site – WordPress MultiSites Network
- Custom Field Query – Meta Value is Array
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- Query all posts in a given taxonomy
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- How do I change database charset when using `wpdb`
- get_posts – get all posts by array of author
- Query “Category A” + 1 post from “Category B” – how?
- Unexpected end of file
- WP_Query To call data from diffrent tables
- new WP_Query with author argument return no results
- How to combine two or more WP_Query?
- Clean up WordPress code that repeats
- WP_Query: “post_parent” and “post_type” combination returning strange results
- Display Featured Post by Categories and Avoid duplicated posts
- How to show optimized list of posts with all their attachment images
- Posts not showing per category after WP_Query?
- wp_query exclude word and category
- WP_query return more results than SQL query. post_count > found_posts
- How do I exclude the lowest level terms in a taxonomy?
- How can I query users by custom role?
- Pagination inside of a edit page
- Problem with is_tax in WP_Query loop
- Removing duplicate values between two wordpress queries
- Error with function in functions.php?
- I am having problem sorting custom post type using WP_Query
- WP_Query and is_page_template() conditional
- Exclude recently updated post from custom WP_Query using multiple loops
- get_posts output always same post
- WordPress Custom Search Form Displaying Unexpected Results
- difference between querying database and using the loop
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- How to do logical OR in terms in WP Query?
- Limit number of posts in loop
- How do I get Woocommerce product variation name and variation description in a WP_Query?
- Slow Query On Search
- Loop posts based on permalink term
- Error in meta_query not get result
- Does putting queries within loops cause an issue on WordPress?
- Custom wp_query – I’m getting ‘all’ post, not the specific post in the query
- How to get current page nearest parent id?
- How to create Page templates for showing Blog posts in different layouts?
- wp Query Posts to display in Nivo Slider
- How to get only ONE category of “Portfolio” posts to display on main page rather than ALL categories?
- Determining what post is displayed out of total posts found
- Strange behaviour of hierarchical taxonomy archive
- Is it normal that get_post() gets run 300 times and the content of those posts aren’t visible?
- How to sort wordpress posts already selected by WP_QUERY
- WordPress Sub Category Archive, Show Extra Empty Page Number in Pagination
- Doing $wpdb->get_results returns NULL, doing the same query in my DB returns correct value
- SEARCH QUERY PLEASE HELP | call_user_func_array() expects parameter 1 to be a valid callback php
- How to get meta key list efficiently?
- Get posts having meta value between two numbers
- Merge wp-query and get_users
- WP_Query how to add a thumbnail to the first post from the last 5 posts?
- How order by works?
- taxquery taxonomy get terms
- Separate by Category Post Type
- Using modified ‘meta_key’ to set ‘orderby’ in WP_Query?
- WP_Query don’t working with fixed post_id and term_taxonomy
- Combine WP_Query with array of custom data to single loop without breaking the pagination
- Query posts in current category but not attachment format
- WP_Query with Pagination and orderby meta_value_num showing duplicates
- Using orderby with 2 meta keys
- wp_query – Modify $query to include duplicate content
- Optimising specific Query with ACF meta objects
- Query to get all the posts of more than 2 meta_value having same meta_key?
- Slow getting posts from category
- Query specific number of posts for each post type in specific order
- Avoiding page loop
- Query Users by post count, last 30 days and display each users post count according to post type
- how do I exclude child categories from a wp_query?
- How to create a loop inside WP_Query?
- how to show only catergory titles on a page in wordpress
- Display Featured image from custom post type category (custom taxonomy) wise
- new WP_Query with order args – no more distinction between categories
- How to make OR condition in WP_Query