Okay, I’ve got it sorted.
I found a post on here with something similar; WordPress wasn’t resetting back into the main loop.
So my code is now:
/* Show roles metabox */
function show_roles_metabox() {
global $post;
$tempPost = $post;
wp_nonce_field(basename(__FILE__), 'role_nonce');
$pro_areas = array(
'One',
'Two',
'Three'
);
$args = array(
'post_type' => 'proarea',
'publish_status' => 'publish',
'posts_per_page' => -1,
'order' => 'ASC'
);
$the_query = new WP_Query($args);
if($the_query->have_posts()) {
echo '<ul>';
while ( $the_query->have_posts()) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
}
wp_reset_postdata();
/*
$mcpt_query = array();
$the_query = get_posts('post_type=proarea');
foreach ( $the_query as $post ) : setup_postdata( $post );
$mcpt_query[] = array(
'title' => get_the_title($post->ID)
);
endforeach;
wp_reset_query();
print_r($mcpt_query);
*/
$post = $tempPost;
echo '<span><label for="pro_area">Professional Area: </label></span>';
echo '<select name="pro_area">';
foreach($pro_areas as $pro_area) {
if($pro_area == get_post_meta($post->ID, 'pro_area', true))
echo '<option selected>'. $pro_area .'</option>';
else
echo '<option>'. $pro_area .'</option>';
}
echo '</select>';
}
What I did was set global $post, and also $tempPost the same.
After the “reset”, I updated $post with what was stored in $tempPost.
The permalink stays the same, I an change the options, and all the areas are displayed.
Hopefully this should allow the areas to be loading in and saved.