title: Wordpress MySQL - custom meta key order by key and date
body: <p>I have a meta key which is set by a select drop down so a user can select an option between 1 and 14 and then save their post. I want the posts to display on the page from 1 to 14 ordered by date but if the user creates a new set of posts the next day I also want this to happen so you have posts 1 to 14 each day displaying in that order.. the SQL i have so far is as follows </p>
  
  <pre><code>    SELECT  SQL_CALC_FOUND_ROWS
              wp_postmeta.meta_key, 
              wp_postmeta.meta_value,
              wp_posts.*
         FROM wp_posts  
   INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
        WHERE 1=1
          AND wp_posts.post_type = 'projectgallery'
         AND (      wp_posts.post_status = 'publish' 
                 OR wp_posts.post_status = 'private')
         AND (wp_postmeta.meta_key = 'gallery_area' )
    GROUP BY wp_posts.post_date asc
    ORDER BY CAST(wp_postmeta.meta_value AS UNSIGNED) DESC,
             DATE(wp_posts.post_date) desc;
  </code></pre>
  
  <p>Which gives me the following output noticte thatthe posts entered at different dates with either 1 or 3 show up in sequence, ideally i want the latest ones to display directly after 14 so it starts over again. the number 14 should not be static either as if someone adds another option to the select then it will increase and decrease if an option is removed.
  <img src="https://i.stack.imgur.com/xTJEl.jpg" alt="enter image description here"></p>