Title: Query loop in reverse order.
Last modified: August 30, 2016

---

# Query loop in reverse order.

 *  Resolved [HeroGreg](https://wordpress.org/support/users/herogreg/)
 * (@herogreg)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/query-loop-in-reverse-order/)
 * I have a Timeline on a page like this one: [http://codepen.io/NilsWe/full/FemfK/](http://codepen.io/NilsWe/full/FemfK/)
 * When I go to edit the page, each new entry in the loop has to be dragged to the
   top of the list, because when I add a new entry it automatically adds it to the
   bottom.
 * Therefore, on the page where the item is displayed, I want it to appear in reverse
   order.
 * My code is:
 *     ```
       <?php $timelinefields = CFS()->get('timeline-fields'); ?>
                   <div class="timeline group">
                   <div class="timeline-title">
       				<div class="timeline-text">
       					<?php echo CFS()->get('timeline-title'); ?>
                       </div>
                   </div>
       <? foreach ($timelinefields as $timelinefield) : ?>
                           <div class="<?=($c++%2==1)?"item-even":"item-odd"?> item">
                                   <span class="role-field"><?= $timelinefield['timeline-role'] ?></span>
                             <p>
                                   <span class="location-field"><?= $timelinefield['timeline-location'] ?></span>
                                   <span class="time-field"><?= $timelinefield['timeline-date'] ?></span><br />
                                   <span class="description-field"><?= $timelinefield['timeline-experience-activities'] ?></span>
                               </p>
                           </div>
       <? endforeach ?>
       ```
   
 * Thanks
 * [https://wordpress.org/plugins/custom-field-suite/](https://wordpress.org/plugins/custom-field-suite/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Srikanth Kamath](https://wordpress.org/support/users/tskamath/)
 * (@tskamath)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/query-loop-in-reverse-order/#post-6354495)
 * hi, the array returned by CFS()->get() is a array, hence you can sort the array
   [http://php.net/manual/en/array.sorting.php](http://php.net/manual/en/array.sorting.php)
 *  Thread Starter [HeroGreg](https://wordpress.org/support/users/herogreg/)
 * (@herogreg)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/query-loop-in-reverse-order/#post-6354496)
 * Thanks for the response. I understand it’s returning an array though I’m not 
   familiar with how to modify my code to do what I’m asking.
 *  [Srikanth Kamath](https://wordpress.org/support/users/tskamath/)
 * (@tskamath)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/query-loop-in-reverse-order/#post-6354501)
 * hi, not tested but will put you in the direction
 *     ```
       //check the array //
       var_dump($timelinefields); 
   
       $sortArray = array(); 
   
       foreach($timelinefields as $item){
           foreach($item as $key=>$value){
               if(!isset($sortArray[$key])){
                   $sortArray[$key] = array();
               }
               $sortArray[$key][] = $value;
           }
       } 
   
       $orderby = "timeline-date"; //change this to whatever key you want from the array
       array_multisort($sortArray[$orderby],SORT_DESC,$timelinefields);
   
       // check the sorted arrary //
       var_dump($timelinefields);
       ```
   
 * [http://php.net/manual/en/function.array-multisort.php](http://php.net/manual/en/function.array-multisort.php)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Query loop in reverse order.’ 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/)

 * 3 replies
 * 2 participants
 * Last reply from: [Srikanth Kamath](https://wordpress.org/support/users/tskamath/)
 * Last activity: [10 years, 10 months ago](https://wordpress.org/support/topic/query-loop-in-reverse-order/#post-6354501)
 * Status: resolved