setup_postdata()
does not assign the global$post
variable so it’s
important that you do this yourself. Failure to do so will cause
problems with any hooks that use any of the above globals in
conjunction with the$post
global, as they will refer to separate
entities.
So you need to do this:
global $post; // This...
foreach ($post_types1 as $post_type1) {
$post = $post_type1; // ...and this.
setup_postdata( $post_type1 );
// etc.
}
wp_reset_postdata();
Related Posts:
- When should you use WP_Query vs query_posts() vs get_posts()?
- How to use the_posts_navigation for wp_query and get_posts?
- WP_Query vs get_posts
- Get posts from Network (Multisite)
- How to order by post_status?
- Using get_posts vs. WP_Query
- Delete all posts from WordPress except latest X posts
- Sanitation needed for WP_Query or get_posts calls?
- Differences Between WP_Query() and get_posts() for Querying Posts?
- get_posts with multiple categories
- get_template_part in for loop
- Use of caller_ get_ posts
- How-to exclude terms from the main query the most performant way?
- Is it possible to select against a post’s parent’s fields with WP_Query?
- Query all posts where meta value is empty
- Get posts by meta data OR title
- Meta Query with date and time on the same Day before given time
- Get posts with condition on comment meta value
- Function to check if author has posted within the last x days
- Use post__in and post__not_in together?
- What should I use, get_posts or wp_query for less CPU load?
- Different Results with query(‘s=computer’) vs get_posts(‘s=computer’)?
- How to get post from all Blog Multisite to the Main Site?
- WP Query post meta value
- Get all posts without tags
- How to find out what “Blog pages show at most” is set to [duplicate]
- Count posts returned by get_posts in external PHP script
- Trying to check and see if a post has a featured image outside of the main loop
- WP_query category__in not working, only pulls from first category
- Adding multiple post queries with parent and children to page – Best Way
- How do you Query posts with nothing in common?
- WP_Query, tax_query and term_meta: How to?
- Get posts for last working week in WP_Query
- get_posts – get all posts by array of author
- Creating a custom search for a specific post type
- Get posts for which a custom field is not present, with get_posts
- get_posts() not working with multiple statuses
- Return only post(s) which have post_excerpt
- Return Taxonomy/Term Information with Posts (WP_Query/get_posts)
- Help with WP_Query – Too many mySQL queries
- add active class based on permalink and url
- Weird orderby => post__in issue
- Why does get_posts only show results for Admins or logged-out users?
- WP_Query post_parent parameter always returns children of current page
- get_post_meta slowing down my page load (in a plugin)
- Get posts by list of post IDs ordered by those IDs?
- How to count posts with specific arguments
- Check return value of get_posts
- Reset WordPress Post Query to default
- Best choice for multiple loop in page?
- Get all posts which was posted on X Days WordPress
- Query post with meta value in set of values
- meta_query: check if number exists
- get_posts output always same post
- get_posts always returning the same number of posts = 5
- “paged” in WP_Query returns 0 posts
- get_posts() and global variables
- complex get_posts() query to select child pages
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Check if searched number is within the post meta value
- get_posts custom field
- How to apply a function to a metadata value before launch a WP Query?
- Posts query according to meta box date
- Woocommerce: order posts by meta key
- WP_User_Query and user posts
- How to access $wp_query object from array of posts given by get_posts?
- Function using get_posts() with tax_query not working when called from functions.php
- get_posts query matches too many results
- Search for pages with permalink
- How to query for a page, get data, then query for child pages of that page
- Why always one post missing
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- How to add date_query to meta_query array
- get_posts query is taking about 40 seconds to execute
- Populate select list with meta values from all posts of a Custom Post Type
- get_posts return only first result
- Related posts queries
- How to get meta key list efficiently?
- how to get wp_query posts only first letter of alphabet A?
- Get posts with any value in attribute
- Slow query when selecting with large meta query or post__in
- I cannot get tax_query in get_posts() to work with custom taxonomy
- Getting the last X posts, but in ascending order of time
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Mathematical operations on custom field values? (updated)
- Display posts from catagories
- Both WP_Query and get_posts returning 1 post
- When should you use WP_Query vs query_posts() vs get_posts()?
- get_posts works but new wp_query doesn’t
- Why WP_Query in functions.php is not working when get_posts works?
- Retrieve posts in custom post type and specific taxonomies
- Query specific number of posts for each post type in specific order
- tax_query not working properly with get_posts
- How to replecate the _fields parameter in custom REST api endpoint
- WordPress extremely slow when using get_posts with multiple meta_query relations
- Empty query on Custom Post Type, using WP_Query or get_posts
- A Depth Like Parameter For “get_posts”
- Sort by multiple columns using get_posts
- How to cache wordpress get_posts query using transients?