title: Combining foreach statements in Wordpress
body: <p>I have a Wordpress website and I have a gallery listed with an image and url for each item. However I can't seem to combine the foreach statements. I always get errors. I know I am close, I think I just need to re-arrange things a bit. Thank you! </p>
  
  <pre><code>&lt;?php 
  foreach($latest_projects as $post) : setup_postdata($post);
  //get image
  $recent_project_thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'recent-work');
  
  foreach ($categories as $cat ) :
  //get image
  $categories = get_terms('gallery_cats');
  ?&gt; 
  
  &lt;li&gt;&lt;a href="https://website.com/&lt;?php echo $cat-&gt;slug; ?&gt;"&gt;&lt;img src="&lt;?php echo $recent_project_thumb[0]; ?&gt;" alt="&lt;?php the_title(); ?&gt;" width="162" height="100" class="imgstyle" /&gt;&lt;/a&gt;&lt;/li&gt;
  
  &lt;?php endforeach; ?&gt;
  </code></pre>