I have a custom post type set up with Advanced Custom Fields. I would like to display and order my posts in groups. The groups are states of the United States, so I have 50 groups.
Should I perform one query per state or is there a way to create one query that will cycle through all the different ( key : value ) (states) values and echo them out to the page in their respective groups?
<?php $posts = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'school', 'meta_key' => 'state', 'meta_value' => 'Texas' )); if( $posts ): ?> <?php foreach( $posts as $post ): setup_postdata( $post ) ?> <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </li> <?php endforeach; ?> <?php wp_reset_postdata(); ?> <?php endif; ?>
This is the standard ACF query by meta value.