title: How to order wordpress posts by a custom field date?
body: <p>I am making an event sidebar section that will only display the next 3 events. I have got the custom post type and custom fields all working but I can seem to figure out how to order the posts by the start date of the events, which is a custom field value. Is there a php function that can compare dates and organize them into a certain order. I think it would also have to hold the post-id with the newly arranged dates so that when I read through the values, i can display the appropriate post with that date.</p>
  
  <p>Does anyone have a certain direction to steer me in?</p>
  
  <p>I think this is what I need to do:</p>
  
  <ol>
  <li>Read through the posts and grab the dates</li>
  <li>Sort the dates with the post-id associated with those dates</li>
  <li>Read through the sorted dates and re-display the first 3 posts by post-id</li>
  </ol>
  
  <p>I get lost on how to code that though... This is what I have so far. This code just displays them by their publish dates in wordpress.</p>
  
  <pre><code>&lt;?php query_posts('post_type=events');
              if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
                  &lt;?php $dateStart = get_post_meta($post-&gt;ID, 'date-start', true);?&gt;
                  &lt;div class="date"&gt;&lt;?php echo $dateStart; ?&gt;&lt;/div&gt;
  
  &lt;?php endwhile; endif; wp_reset_query();  ?&gt;
  </code></pre>