Title: WordPress &#8211; Order $posts
Last modified: August 21, 2016

---

# WordPress – Order $posts

 *  [Shellanza](https://wordpress.org/support/users/shellanza/)
 * (@shellanza)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/wordpress-order-posts/)
 * Ciao guys,
    I’m getting mad with this issue. I have a script in a WP theme that
   it’s supposed to retrieve some data. It works ok but I need it does the thing
   in alphabetic mode and this seem to be… quite hard!
 * I dig into the web looking for plugin with no success and even modifing the core
   like they say here [http://codex.wordpress.org/Alphabetizing_Posts](http://codex.wordpress.org/Alphabetizing_Posts)
 * I need help because I’m stucked. The url where this happen is this: [http://www.jre.it/?s=&geo-radius=50&geo-lat=&geo-lng=&categories=0&locations=0&dir-search=yes&post_type=ait-dir-item](http://www.jre.it/?s=&geo-radius=50&geo-lat=&geo-lng=&categories=0&locations=0&dir-search=yes&post_type=ait-dir-item)
 * If yiu try to press ENTER just in the forst field (Ristorante, Chef, Città) the
   order is not in alphabetic mode because the first result is “Trippini”.
 * Here what I have in category.php on themes folder:
 *     ```
       {extends $layout}
       {block content}
       {if $posts}
               <article id="post-{$post->id}" class="{$post->htmlClasses}">
                       <header class="entry-header">
                           <h1 class="entry-title">
                               <span>{$category->title}</span>
                           </h1>
                       </header>
                       {if strlen($category->description) !== 0}
                       <div class="entry-content">
                           {!$category->description}
                       </div>
                       {/if}
               </article><!-- /#post-{$post->id} -->
               {include snippets/content-nav.php location => 'nav-above'}
               {include snippets/content-loop.php posts => $posts}
               {include snippets/content-nav.php location => 'nav-below'}
           {ifset $themeOptions->advertising->showBox4}
           <div id="advertising-box-4" class="advertising-box">
               {!$themeOptions->advertising->box4Content}
           </div>
           {/ifset}
       {else}
           {include snippets/nothing-found.php}
       {/if}
       {/block}
       ```
   
 * And this is the code of content-loop-dir-search.php that seem to be the result
   page:
 *     ```
       {foreach $posts as $item}
       {first}<ul class="items">{/first}
           <li class="item clear{ifset $item->packageClass} {$item->packageClass}{/ifset}">
               {if $item->thumbnailDir}
               <div class="thumbnail">
                   <a href="{!$item->link}"><img src="{timthumb src => $item->thumbnailDir, w => 100, h => 100}" alt="{__ 'Item thumbnail'}"></a>
               </div>
               {/if}
               <div class="description">
                   <h3>
                       <a href="{!$item->link}">Ristorante {$item->post_title}</a>
                   </h3>
                       <?php
                       //var_dump($options);
                       global $wpdb;
                       $sql = "SELECT meta_value FROM ".$wpdb->prefix."postmeta WHERE post_id=".$item->ID." AND meta_key LIKE '%_ait%'";
                       $itemMeta = $wpdb->get_results($sql);
                       $itemMetaValue = unserialize($itemMeta[0]->meta_value);
                       //var_dump($itemMetaValue);
                       echo
                       "Chef: ".$itemMetaValue['nome-chef']." ".$itemMetaValue['cognome-chef']."<br/>"
                       .$itemMetaValue['address']."<br/>"
                       .$itemMetaValue['cap']." ".$itemMetaValue['citta']." (".$itemMetaValue['provincia'].")<br/>"
                       ."T: ".$itemMetaValue['telephone']."<br/>";
                       ?>
               </div>
               <hr class="bg" />
           </li>
       {last}</ul>{/last}
       {/foreach}
       ```
   
 * Thanks everybody for your help.
 * CM

The topic ‘WordPress – Order $posts’ is closed to new replies.

## Tags

 * [order](https://wordpress.org/support/topic-tag/order/)
 * [post](https://wordpress.org/support/topic-tag/post/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Shellanza](https://wordpress.org/support/users/shellanza/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/wordpress-order-posts/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
