Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <?php
  2. $the_query = new WP_Query(array(
  3. 'post_type' => 'post',
  4. 'post_status' => 'publish',
  5. 'meta_key' => 'colors',
  6. ));
  7.  
  8.  
  9. $results = [];
  10. while ( $the_query->have_posts() ) {
  11.  
  12. $the_query->the_post();
  13. $credits = get_field('colors');
  14.  
  15. if( !empty($color) ) {
  16.  
  17. foreach( $colors as $color ) {
  18. $results [$color][]=array(
  19. 'title' => get_the_title(),
  20. 'link' => get_attachment_link(),
  21. 'img' => get_field('photo')
  22. );
  23. }
  24. }
  25. }
  26.  
  27. foreach ($results as $color => $posts) {
  28.  
  29. echo '<div><h2>'.$color.'</h2>';
  30.  
  31. foreach($posts as $post) {
  32. echo '<div><a href="'.$post['link'].'">'.$post['title'].'</a><img src="'.$post['img']['url'].'"></div>';
  33. }
  34.  
  35. echo '</div>';
  36. }
  37.  
  38. wp_reset_postdata();?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement