Title: Ordering Custom Post Types by Custom Fields
Last modified: August 20, 2016

---

# Ordering Custom Post Types by Custom Fields

 *  [bencarter78](https://wordpress.org/support/users/bencarter78/)
 * (@bencarter78)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/ordering-custom-post-types-by-custom-fields/)
 * Hi there
 * I’m trying to create a loop of all my custom post titles and their custom fields.
   I want to order them by a custom field called ‘vacancy-company’ but it just lists
   them by post date.
 * Here’s my code…
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   The maximum number of lines of code that you can post in these forums is **ten
   lines**. Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * Can someone tell me what I’m doing wrong please?!!!
 * Thank you!

Viewing 1 replies (of 1 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/ordering-custom-post-types-by-custom-fields/#post-2699100)
 * Since I can’t see your code, I can’t be sure, but you should probably be able
   to add a couple of arguments to your query_posts(), something like this:
 *     ```
       $args = array(
          'paged' => $paged,  // Assuming this was already there
          'meta_key' => 'vacancy-company',  // Add this
          'orderby' => 'meta_key',  // Add this
          'order' => 'ASC',  // Probably need this
       );
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Ordering Custom Post Types by Custom Fields’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [orderby](https://wordpress.org/support/topic-tag/orderby/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/ordering-custom-post-types-by-custom-fields/#post-2699100)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
