Better way to list links with different meta values using same meta key?
This works, but I will need it to make 8 different lists on the page, using same meta key but 8 different meta values. Is there a more efficient way to achieve this rather than repeating the same code 8 times?
?php
$posts = get_posts(array(
'numberposts' = -1,
'post_type' = 'page',
'meta_key' = 'my_meta_key',
'meta_value' = 'meta_value_1'
));
if( $posts ): ?
h4Pages with Meta Value 1:/h4
ul
?php foreach( $posts as $post ):
setup_postdata( $post );
?
li
a href=?php the_permalink(); ??php the_title(); ?/a
/li
?php endforeach; ?
/ul
?php wp_reset_postdata(); ?
?php endif; ?
?php
$posts = get_posts(array(
'numberposts' = -1,
'post_type' = 'page',
'meta_key' = 'my_meta_key',
'meta_value' = 'meta_value_2'
));
if( $posts ): ?
h4Pages with Meta Value 2:/h4
ul
?php foreach( $posts as $post ):
setup_postdata( $post );
?
li
a href=?php the_permalink(); ??php the_title(); ?/a
/li
?php endforeach; ?
/ul
?php wp_reset_postdata(); ?
?php endif; ?
Topic meta-value get-posts Wordpress
Category Web