I don’t think this is what birgire intended (thank you though!) but this is my revised code after doing some research. Much shorter, and meets my needs, but I’d still like eyes on it just to be sure I’m not doing something stupid. The NOT IN array ” was to only retrieve pages that have a meta_value set for this key – it worked perfectly, but maybe there’s a better way to do this?
<?php
$posts = get_posts(array(
'numberposts' => 500,
'post_type' => 'page',
'meta_key' => 'my_meta_key',
'meta_value' => array(''),
'meta_compare' => 'NOT IN',
'orderby' => 'meta_value',
'order' => 'ASC'
));
if( $posts ): ?>
<h4>Posts with a Value in my_meta_key:</h4>
<table>
<?php foreach( $posts as $post ):
setup_postdata( $post );
?>
<tr>
<td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td>
<td><?php echo get_post_meta( get_the_ID(), 'my_meta_key', true ); ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php wp_reset_postdata(); ?>
<?php endif; ?>