Title: Sort Loop by Date
Last modified: August 20, 2016

---

# Sort Loop by Date

 *  Resolved [haneedesigns1](https://wordpress.org/support/users/haneedesigns1/)
 * (@haneedesigns1)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/order-loop-by-date/)
 * Hey Guys: Great plugin. I was wondering how to order posts within a loop by date?
   I figured out how to make them expire. I just wasn’t sure where to put the “orderby
   =ASC” Here’s what I currently have as my code:
 *     ```
       $fields = $cfs->get('appearances');
       foreach ($fields as $field) {
   
       if ($field['date'] > date('Y-m-d H:i:s')) {
   
       	echo '<div class="custom-fields"><div class="field-thumbnail"><img src="',$field['image'],'" ></div><div class="appearancesright">';
       	echo '<div class="custom">',date('F j, Y', strtotime($field['date'])),'</div>';
       	echo '<h4>',$field['event'],'</h4>';
          echo '<div class="custom">',$field['time'],'</div>';
       	echo '<div class="custom">',$field['location'],'</div>';
          echo '<div class="custom">',$field['address'],'</div>';
       	echo '<div class="custom">',$field['city_and_state'],'</div>';
          echo '<div class="custom">',$field['event_details'],'</div>';
       	echo '<div class="custom"><a href="',$field['event_website'],'">Event Page</a></div></div>';
       	echo '<div class="clear"></div></div>';
   
          }
       }
       }
       ?>
       ```
   
 * _[Please post code & markup between backticks or use the code button. Your posted
   code may now have been permanently damaged by the forum’s parser.]_
 * [http://wordpress.org/extend/plugins/custom-field-suite/](http://wordpress.org/extend/plugins/custom-field-suite/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Matt Gibbs](https://wordpress.org/support/users/mgibbs189/)
 * (@mgibbs189)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/order-loop-by-date/#post-3518966)
 * (Resolved) posted at [http://uproot.us/forums/questions/1111/sort-loop-posts-by-date](http://uproot.us/forums/questions/1111/sort-loop-posts-by-date)

Viewing 1 replies (of 1 total)

The topic ‘Sort Loop by Date’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-field-suite.svg)
 * [Custom Field Suite](https://wordpress.org/plugins/custom-field-suite/)
 * [Support Threads](https://wordpress.org/support/plugin/custom-field-suite/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-field-suite/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-field-suite/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-field-suite/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Matt Gibbs](https://wordpress.org/support/users/mgibbs189/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/order-loop-by-date/#post-3518966)
 * Status: resolved