$the_query->the_post();
is populating the global $post
with each post in that loop. On front-end queries, you’d normally call wp_reset_postdata()
after running a secondary query loop, but that doesn’t work on the admin side.
Use get_posts
instead of WP_Query
, and iterate over the results with a foreach
loop-
$my_posts = get_posts( $args );
if( !empty( $my_posts ) ){
foreach( $my_posts as $my_post ){
echo $my_post->ID;
echo get_the_title( $my_post );
}
}