Title: WordPress Ordering posts in foreach statement
Last modified: August 20, 2016

---

# WordPress Ordering posts in foreach statement

 *  [drhodes](https://wordpress.org/support/users/dthornborrow/)
 * (@dthornborrow)
 * [14 years ago](https://wordpress.org/support/topic/wordpress-ordering-posts-in-foreach-statement/)
 * I have a for each statement that looks for a Taxonomy by ID and gets all termchildren
   and lists them using a foreach loop. I’m trying to figure out how to order them
   alphabetically by title. Here’s my code:
 *     ```
       $termID = 5;
       $taxonomyName = "apartmentlocation";
       $termchildren = get_term_children( $termID, $taxonomyName );
   
       foreach ($termchildren as $child) {
           $term = get_term_by( 'id', $child, $taxonomyName);
           echo '
       <li><a>name, $taxonomyName ) . '">' . $term->name . '</a></li>
       ';
           }
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [drhodes](https://wordpress.org/support/users/dthornborrow/)
 * (@dthornborrow)
 * [14 years ago](https://wordpress.org/support/topic/wordpress-ordering-posts-in-foreach-statement/#post-2832037)
 * Anybody?

Viewing 1 replies (of 1 total)

The topic ‘WordPress Ordering posts in foreach statement’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [drhodes](https://wordpress.org/support/users/dthornborrow/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/wordpress-ordering-posts-in-foreach-statement/#post-2832037)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
