Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $the_query = new WP_Query(array(
- 'post_type' => 'post',
- 'post_status' => 'publish',
- 'meta_key' => 'colors',
- ));
- $results = [];
- while ( $the_query->have_posts() ) {
- $the_query->the_post();
- $credits = get_field('colors');
- if( !empty($color) ) {
- foreach( $colors as $color ) {
- $results [$color][]=array(
- 'title' => get_the_title(),
- 'link' => get_attachment_link(),
- 'img' => get_field('photo')
- );
- }
- }
- }
- foreach ($results as $color => $posts) {
- echo '<div><h2>'.$color.'</h2>';
- foreach($posts as $post) {
- echo '<div><a href="'.$post['link'].'">'.$post['title'].'</a><img src="'.$post['img']['url'].'"></div>';
- }
- echo '</div>';
- }
- wp_reset_postdata();?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement