As setup_postdata
is messing with global variables that might be (most probably: are) used by other loops (including The Loop), you should always reset these variables to what they should be—according to the main query (i.e., what WordPress thinks the user wanted in the first place).
In addition, setup_postdata
is provided with (a reference to) the $post
global, which might be altered afterwards.
So, yes, setup_postdata
should be accompanied by wp_reset_postdata
.
As you can see in the code, the reset_postdata
function is, in fact, calling setup_postdata
on the original $post
object.
Related Posts:
- How to limit the number of posts that WP_Query gets?
- Should we trust the post globals?
- Random sort within an already sorted query
- How to know if get_posts() failed?
- WordPress Number of Posts Not Changing With posts_per_page
- How to add posts to wp_query result?
- Search query – exact post title match
- posts_per_page doesnt work
- How to start with post number x?
- Exclude posts with empty post_content in wp_query
- Only display a certain number of posts, dependent on how many posts there are available in a query
- Improving WP_Query for performance when random posts are ordered
- Should $found_posts be returned as string in ‘found_posts’ filter hook?
- Get Posts that are in the current month or later
- Exclude the first ‘n’ number of posts of a tag from home page?
- posts_per_page option limits the number of Gallery items
- Why Query is returning empty array?
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- meta_value timestamp older than now
- Do not show children of a category
- Query for first 3 posts to change the look and feel
- Why posts array is empty?
- How to give classname to post if post has no content?
- Exclude some posts from displaying in wp_query based on some condition
- Related Posts function not working
- How to retrieve certain number of images from a wordpress post?
- How to convert query sql to shortcode in wordpress?
- Custom WP_Query not working correctly
- How Can I Always Display A Particular Post First Using WP_Query?
- WordPress Query – Display 5 posts (same post type), each from a given tag
- filter posts based on menu_order
- Show 5 posts and than 3 posts offset with pagination
- wp query custom orderby not custom field
- Sort / Filter Queries
- Advanced Post Display/Pagination/Ordering
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- Displaying Results From Custom Taxonomy Query
- WP_Query retrieve custom posts but not the post showing
- Wp_query WooCommerce products
- Skipping first 3 posts in wp query
- Accessing the post content with WP_Query
- How to output comments number of a post per day?
- wp_enqueue_media() slows down my WP site
- Query posts from different categories in multisite
- wp query with dynamic taxonomies and terms?
- Sorting posts according to view counts not working
- Automatic value for custom fields for posts
- Why won’t my taxonomy query show up?
- WP Query to Get Array of Slugs
- do_shortcode within post query
- WP_Query with ajax handler returns the same posts
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Most liked page not displaying posts
- Query get post,how to add comment box
- How to insert 2 args into 1 Wp_Query for a slideshow
- WP Query – Posts Per Page not working in combination with category__in
- How can I setup a relationship using categories in WordPress?
- how to change the number of posts returned in a specific loop without making it global?
- How i can limit period of post publication?
- Exclude current custom post on single post
- Nested WP_Query breaking loop
- Ignore latest two posts
- post__in not working with pre_get_posts, but post__not_in does work
- Print out last 3 blogposts
- Query posts and filter at query time by value of custom meta
- Getting blog pagination to work on page set as front page
- search blog posts by author first name and or last name
- Very complex post query
- Delete post revisions only for a single post
- On what hook can I get the queried object’s final state?
- unique post in “$args” of wp_query display more than one post
- How to display post list in a table layout (multiple queries in single loop)
- Not all posts showing in query
- Get all custom posts with a certain taxonomy
- WordPress query portfolio posts
- Get latest author posts inside the loop
- Display 3 posts with different HTML markup using a loop
- How to show multiple posts thumbnail, title and date in widget
- Group first, 2nd, 3rd, etc posts by category terms
- Manipulated offset and pagination, can’t display last post anymore
- Query to fetch custom taxonomy along with post title
- How to fetch courses in all languages in WordPress?
- How to display particular set of wordpress post on a webpage?
- Change archive results based on GET request
- Querying posts from current category, using a variable as array argument
- Is it possible to query a category with specified posts?
- Query posts from newest category
- WordPress loop uses unmodified posts array, why?
- Show posts between two Custom Fields date
- Query to get data of a post, if in category?
- Order posts by custom field
- Ordering posts alphabetically by meta keys and title
- Grab next post title in archive page
- Remove duplicated posts in the loop if post has more than one category
- Continuous listing from a custom field
- How to store post rating system data post independent?
- Why I getting only 1 post?
- How to limit post query to only return a total count of items with certain post statuses?
- First post in loop displays twice