Having attempted various work arounds the way I have this to work is to not use the_post(). WP_Query should still work but I have swapped over to get_posts().
$results = get_posts( $args );
foreach ( $results as $p ):
$array[$p->ID] = $p->post_title;
endforeach;
return $array;
Frustrating that this seems to be a problem with certain admin pages.
Here is a ticket related to the issue: https://core.trac.wordpress.org/ticket/18408
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
- Set post number to single posts
- 3 posts from each existing category on one page
- Unable to reset post data in wordpress custom query
- Can’t reset the secondary query by wp_reset_postdata()
- 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?
- order by numeric value for meta value
- numberposts? showposts? posts_per_page?
- $GLOBALS[‘wp_the_query’] vs global $wp_query
- Some doubts about how the main query and the custom query works in this custom theme?
- Set Alias for meta_query arguments in get_posts()
- How can I use order_by to order by two meta_keys without excluding posts that don’t have those keys initialized?
- Loop within a loop?
- How to query only for products with status “in stock” in WooCommerce? [closed]
- Does WordPress sanitize arguments to WP_Query?
- How to get posts in different language from WPML Plugin [closed]
- WP_Query meta_query where meta value ends in space
- Highlighting Sub topic in a post?
- wp_query for the first sticky, then display the rest of the posts excluding the first sticky
- How to get any tag ID
- WP_Query with many meta_query arguments taking a long time to load
- Slow speed and high CPU usage for my code. How to improve it?
- Multiple queries on Home Page – page load/site speed issue
- WordPress custom archive page
- query attachments of parent page if attachments of current page are smaller than …
- Why is this coming back as null? Thats wrong. There is one post
- Retrieve featured image (thumbnail) url from multiple posts with one query
- WP_Query tax_query problem
- Only display authors who have posts
- wp_query() get_col error
- Update Loop with Form
- How to select posts from one category but exclude posts in another category?
- Query Custom Post Type Order By Taxonomy Field
- Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first
- How can you get first post, last post and post count in a category?
- WP_query posts closest to todays date
- Setting get_queried_object
- Sort query by author: 1 author, then others
- How to orderby multiple meta fields if some fields are empty
- WordPress custom post type with meta – how to retrieve with wp_query
- Order by meta value (numeric value lower to higher)
- Wp_query calculate points
- WP Query – Outputting JSON and normal loop of posts
- get data match with extra field value using wp_query for custom post
- Custom query: Get all posts that are from a certain category?
- get_template_part causes 500 error
- Finding WordPress Posts assigned to multiple categories
- The most effective way to split by post type in custom query?
- Does meta_value (array) work with ‘orderby’?
- Get a list of posts by specific category
- WordPress Query String: get_posts(‘cat=5’) vs WP_Query( ‘cat=5’) vs URL: /site/?cat=5
- WP_Query – Adding “offset” posts to the end of the loop
- Shortcode for custom query not returning results when attributes are added
- wp_query is showing posts from other categories
- Multiple wordpress queries with nested output (odd – even)
- Get posts in taxonomy randomly
- Page navigation doesn’t seem to work when I add offset?
- it’s possible make a WP_Query with math operations?
- show posts with range meta key
- Using a Shortcode to List Posts from Multiple Categories
- is_404() – where does this get set?
- wp_query on page template not working (Genesis framework)
- WordPress | WP_Query does not return anything with s=a
- WP_Query Pagination
- WP_Query random ordering not working since 5.4
- Where my home page and font options has gone?
- How to get the latest post list (of the parent custom custom type)
- meta_query compare > not working
- 404 page on custom search pagination
- WP_Query about meta_key and its array value
- Query string order by custom field
- Paging works correctly on local version, but not live?
- Create global array to compare inside a query
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Paginate nested query of child posts
- Hi , i am trying to set the post for 24 hours and with it will be changed
- Own query vars are not displayed
- Show full category tree for a year with all post titles?
- Trying to use “Medium” featured image for custom post type on home page
- Get Current CPT taxonomy category in shortcode
- Display images with same specific value?
- Sort Posts with custom meta key by default which is currently set as optional
- wp_query pagination links producing 404
- How return normal search result using wp_ajax action for wordpress
- Custom post types loop on a page template
- Pagination problem with multiple loops on the same page
- How to query posts from single post format on Genesis framework
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Get posts using multiple values from ACF checkbox as meta query wordpress
- Why ignore_sticky_posts argument is in sticky post query?