wp_reset_query
is meant to be used with a loop, because it resets the global $wp_query
object. get_posts
, on the other hand, just returns an array to be iterated with ie. foreach
. setup_postdata
does not populate the $wp_query
object: https://codex.wordpress.org/Function_Reference/setup_postdata.
For a custom query, you would either use the WP_Query
class, or you could reset your posts array using standard PHP functions like reset.
https://codex.wordpress.org/Function_Reference/wp_reset_query
Related Posts:
- How does reset_postdata restore the post of the main query loop?
- Where should you reset postdata?
- Why should i use wp_reset_postdata()?
- When should you use wp_reset_postdata vs wp_reset_query?
- Trouble with wp_reset_postdata() in Admin Panel
- Reset postdata to custom query in nested queries
- reset to main loop doesnt work
- WP CLI can’t delete plugin related table
- Admin Page Post Id wp_reset_postdata not working
- Set post number to single posts
- 3 posts from each existing category on one page
- Unable to reset post data in wordpress custom query
- What’s causing an infinite loop?
- Calling a function with WP_Query only ever brings the first result
- Correct Way To Run Multiple Queries Sharing Some Base Data
- Why am I getting no results of a query placed after another query?
- Posts with at least 3 tags of a list of tags
- Get post count of current loop when using multiple queries on one page
- How to uniquely identify queries?
- Use WP_Query with a custom SQL query
- Pagination not working for Custom search form & custom result template
- Using next/previous_posts_link with customised search
- How to display most recent posts that haven’t already been displayed with WP_Query?
- Display featured products through custom loop in WooCommerce 3 [closed]
- How to detect custom query inside `posts_where` hook?
- Is temporarily overwriting $wp_query a bad idea?
- Array Chunks and Inserting Varying HTML in WP_Query
- Filter user list that meta_value is empty
- Query wp_usermeta alongside wp_users
- How to output different posts per page?
- Multiple WP_Query loops with Pagination Not Working
- WooCommerce Only OnSale Products Loop Snippet [closed]
- WP_Query times out
- ACF – Get lowest & highest value from field
- What format does the meta_query TIME type require?
- How to find a post id using the post_excerpt?
- wp_query add arguments using array_push if variable met
- tax_query: Order by slug?
- WP_Query date_query – Use unix timestamp?
- WP_Query filter and order by meta ordering by wrong joined table
- WP_Query last five posts, simply ordered by meta_value
- WP_Query “OR”: Find posts by ID, Name or Post Title?
- Querying A Post That Includes Two Taxonomies Using JSON Rest API
- WP_Query condition affects posts_per_page count
- Order by title without taking into account ‘the’
- Set global $wp_query/$post variable for dynamic page generation
- Display tags with random thumbnail from selection of posts with that tag
- Is there a way to work with a specific the_field from an already queried post? [closed]
- slow WP_Query for non-admin user
- Changing sort order for presentation by Jetpack infinite scroll
- How to search for posts given post_content AND post_excerpt using WP_Query?
- Filter and Order by Multiple Custom Meta Values
- WP_Query Attachment adds additional attachment count and need to link attachment to post url
- Does the WP_Query ‘private’ argument for post status only apply to privately published content?
- Query most popular terms by taxonomy over 2 week period
- WordPress | Date not always appear [duplicate]
- WordPress posts for multiple years
- Filter posts by comparing custom meta value against postdate
- Query posts that contain video?
- “paged” in WP_Query returns 0 posts
- How to show one post different from the rest?
- Reduce number of SQL queries inside WP_Query loop to fetch author data
- Count posts per taxonomy else change taxonomy if less than x number
- Combine 2 arrays in a query parameter
- Add ACF field in a query
- Set front_page programatically after user login via query, while leaving site option alone
- Running multiple WP_Query
- Check if searched number is within the post meta value
- How to split a post and intercalate elements from a loop
- How to echo woocommerce category name
- Find all product ID from array of customfield
- Printing a variable inside a custom WP_Query
- Notice thrown when creating numeric pagination on custom query
- and tag not working
- Hiding carousel indicators if there’s only one post
- add_query_arg to compare and display events from a certain date
- WP Query get only 1 post (sticky, not sticky etc)
- How to query all posts in CPT + only posts with custom tax in another CPT?
- WooCommerce sort by SKU
- Custom Meta Query doesn’t work the same on two site
- Order post by modified date
- Redirect logged in users from a custom post type archive page if they don’t have a specific role
- Sorting query_posts() with a complex orderby filter
- Order 2 meta_queries differently in WP_Query?
- WP Query filters active on wrong query
- Not able to fetch woocommerce variation sales products for particular category products
- Global page ID variable empty error
- Gather same custom field values in one value in a select tag with wp_query
- Order Posts By Youtube Views
- WP Query with sticky posts and tax_query
- Declare inline background image in functions.php
- WP_Query for attachments without duplicating post_parent and displaying tagged image
- Query posts by custom fields
- Showing posts from 4 categories along with all latest posts
- Searching in specific custom post type
- WP Query Obj: Set value to be unequal | Hide media by admin
- WordPress pagination returns the same posts
- How to get all post_id and meta_value using meta_key in wp_postmeta table
- How can I get taxonomy term name using term slug & post ID using build in WordPress function or class?
- Why does wp_query only display the most recent post when using order ASC?