title: Sorting posts by week/month/all time
body: <p>So I have managed to sort my posts with some basic settings. I want to change this from date-asc, date-dec, comments etc week, month, all time. I also was hoping to incorporate the following code which would sort the top voted posts only, instead of all posts</p>
  
  <pre><code>meta_key=votes_count&amp;orderby=meta_value_num&amp;order=DESC&amp;posts_per_page=10
  </code></pre>
  
  <p>My working top rated page at the moment, which sorts my date-asc, title etc:</p>
  
  <pre><code>&lt;?php
  if( isset($_GET['o']) &amp;&amp; $_GET['o'] != '')
        {
            $order = $_GET['o'];
            switch($order)
            {
              case 'date-asc': $orderby = 'order=ASC';
                          $msg = 'Date Ascending';
                            break;
  
              case 'date-desc': $orderby = 'order=DESC';
                          $msg = 'Date Descending(default)';
                            break;
  
              case 'date-mod': $orderby = 'orderby=modified';
                              $msg = 'Date Modified';
                             break;
  
              case 'title-asc': $orderby = 'orderby=title&amp;order=ASC';
                              $msg = 'Title A-Z';
                              break;
  
              case 'title-desc': $orderby = 'orderby=title&amp;order=DESC';
                              $msg = 'Title Z-A';
                              break;
  
              case 'comment': $orderby = 'orderby=comment_count';
                              $msg = 'Comment Count';
                              break;
            }
        }
        else
        {
            $orderby = 'order=DESC';
            $msg = 'Date Descending (default)';
        }
  ?&gt;
  
  &lt;div id="content"&gt;
  
  &lt;div id="sorter-container"&gt;
  
  
  &lt;h2 id="sort-heading"&gt;Posts ordered by:&lt;?php echo $msg; ?&gt;&lt;/h2&gt;
      &lt;select id="order-by"&gt;
          &lt;option value="date-desc" &lt;?php echo (!isset($order) || $order == '' || $order == 'date-desc')? 'selected="selected"':''; ?&gt;&gt;Date Desc. (default)&lt;/option&gt;
          &lt;option value="date-asc" &lt;?php echo ($order == 'date-asc')? 'selected="selected"':''; ?&gt;&gt;Date Asc&lt;/option&gt;
          &lt;option value="date-mod" &lt;?php echo ($order == 'date-mod')? 'selected="selected"':''; ?&gt;&gt;Date Modified&lt;/option&gt;
          &lt;option value="title-desc" &lt;?php echo ($order == 'title-desc')? 'selected="selected"':''; ?&gt;&gt;Title Desc.&lt;/option&gt;
          &lt;option value="title-asc" &lt;?php echo ($order == 'title-asc')? 'selected="selected"':''; ?&gt;&gt;Title Asc.&lt;/option&gt;
          &lt;option value="comment" &lt;?php echo ($order == 'comment')? 'selected="selected"':''; ?&gt;&gt;Comments Count&lt;/option&gt;
      &lt;/select&gt;
  &lt;/div&gt;
      &lt;script type="text/javascript"&gt;
              var orderby = jQuery('#order-by');
              var str;
              orderby.change(function(){
                  str = jQuery(this).val();
                   window.location.href = "&lt;?php echo home_url(); ?&gt;/top-rated/?o="+str;
              });
    &lt;/script&gt;
  </code></pre>
  
  <p><strong>EDIT2:</strong>
  Ok, so here is what I have, it no longer works, so I just continued and added week/month/alltime to where I think it should go (I know its not correct, but I wasnt sure how to limit the sort to just 7 days etc.</p>
  
  <pre><code>&lt;?php
  if( isset($_GET['o']) &amp;&amp; $_GET['o'] != '')
        {
            $order = $_GET['o'];
            switch($order)
            {
              case 'week': $orderby = 'meta_key=votes_count&amp;orderby=meta_value_num&amp;order=DESC&amp;WEEK&amp;posts_per_page=10';
                          $msg = 'This Week (default)';
                            break;
  
              case 'month': $orderby = 'meta_key=votes_count&amp;orderby=meta_value_num&amp;order=DESC&amp;MONTH&amp;posts_per_page=10';
                              $msg = 'This Month';
                             break;
  
              case 'alltime': $orderby = 'meta_key=votes_count&amp;orderby=meta_value_num&amp;order=DESC&amp;ALLTIME&amp;posts_per_page=10';
                              $msg = 'All Time';
                              break;
        else
        {
            $orderby = 'order=DESC';
            $msg = 'This Week (default)';
        }
  ?&gt;
  
  &lt;div id="content"&gt;
  
  &lt;div id="sorter-container"&gt;
  
  
  &lt;h2 id="sort-heading"&gt;Posts ordered by:&lt;?php echo $msg; ?&gt;&lt;/h2&gt;
      &lt;select id="order-by"&gt;
          &lt;option value="week" &lt;?php echo (!isset($order) || $order == '' || $order == 'week')? 'selected="selected"':''; ?&gt;&gt;This Week (default)&lt;/option&gt;
          &lt;option value="month" &lt;?php echo ($order == 'month')? 'selected="selected"':''; ?&gt;&gt;This Month&lt;/option&gt;
          &lt;option value="alltime" &lt;?php echo ($order == 'alltime')? 'selected="selected"':''; ?&gt;&gt;All Time&lt;/option&gt;
      &lt;/select&gt;
  &lt;/div&gt;
  </code></pre>