title: Divide query result into lists based on field
body: <p>I'm creating a custom page with Wordpress and need to divide my query results into lists based on a tag. I know there's a Wordpress stack exchange but this seems more like a basic PHP function to me. The only thing I found on the Wordpress stack said to execute new queries based on the tag name.</p>
  
  <p>There must be a more efficient way...</p>
  
  <p>I'm new to PHP. To complicate matters further I've always struggled with loops but am grasping the concept more and more everyday.</p>
  
  <p>Here's the logic I'm looking to achieve:</p>
  
  <p>Query the DB and Get the "title" of posts tagged with "Red, Green, Blue, Yellow". This part I can do with the <code>WP_Query()</code> function, no problem there... The trouble is the next part.</p>
  
  <p>Loop over the query and output: </p>
  
  <pre><code>&lt;ul id="red"&gt;
  &lt;li&gt;Output title of first post tagged with Red&lt;/li&gt;
  &lt;li&gt;Output title of second post tagged with Red&lt;/li&gt;
  &lt;li&gt;Output title of third post tagged with Red&lt;/li&gt;
  &lt;!--[etc...]--&gt;
  &lt;/ul&gt;
  &lt;ul id="green"&gt;
  &lt;li&gt;Output title of first post tagged with Greeen&lt;/li&gt;
  &lt;li&gt;Output title of second post tagged with Green&lt;/li&gt;
  &lt;li&gt;Output title of third post tagged with Green&lt;/li&gt;
  &lt;!--[etc...]--&gt;
  &lt;/ul&gt;
  &lt;!--[continue for other colors requested in the query]--&gt;
  </code></pre>
  
  <p>End the loop</p>
  
  <p>I understand the first loop that would iterate over the results and output the title of all the records, I'm just confused about how to loop over the results and further divide by the color.</p>
  
  <p>Any help is greatly appreciated.</p>