Title: query_posts Order by Custom Field
Last modified: August 30, 2016

---

# query_posts Order by Custom Field

 *  Resolved [red5](https://wordpress.org/support/users/red5/)
 * (@red5)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/query_posts-order-by-custom-field/)
 * My customer wants to order posts by a custom field (meta value). his code looks
   like this:
    query_posts($query_string . ‘&orderby=title&order=ASC’); if(have_posts()):
   while(have_posts()) : the_post();
 * He wants to order the posts by meta called “list_order” instead of by title. 
   I haven’t been able to figure out how. Suggestions?

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

 *  [John Parris](https://wordpress.org/support/users/mindctrl/)
 * (@mindctrl)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/query_posts-order-by-custom-field/#post-6332719)
 * As noted on the [query_posts page](https://codex.wordpress.org/Function_Reference/query_posts),
   it’s best not to use that at all. Use [WP_Query](https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters)
   or the [pre_get_posts](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts)
   hook instead.
 *  Thread Starter [red5](https://wordpress.org/support/users/red5/)
 * (@red5)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/query_posts-order-by-custom-field/#post-6332721)
 * I completely agree. I was hired to work on code someone else wrote. FWIW, here’s
   how I got it to function, where I sort by “list_order.”
 * `query_posts($query_string . &meta_type=NUMERIC&orderby=meta_value_num&meta_key
   =list_order`

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

The topic ‘query_posts Order by Custom Field’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [red5](https://wordpress.org/support/users/red5/)
 * Last activity: [10 years, 10 months ago](https://wordpress.org/support/topic/query_posts-order-by-custom-field/#post-6332721)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
