Title: Sort custom fields
Last modified: August 19, 2016

---

# Sort custom fields

 *  [Fredriks](https://wordpress.org/support/users/fredriks/)
 * (@fredriks)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/sort-custom-fields/)
 * Hello,
 * I have digged the hole day long for being able to sort custom fields with only
   the help of the query_posts() attribute.
 * I find it hard to implement the technique described here: [http://wordpress.org/support/topic/sort-posts-by-custom-field-numeric-value?replies=12](http://wordpress.org/support/topic/sort-posts-by-custom-field-numeric-value?replies=12)
 * My “problem” is that I have both numbers and letters in the custom_fields like
   the following example:
 * **meta_key meta_value**
    cow_type belgienblue cow_legs 40 cow_nose 1 cow_type
   Awsome-Cow cow_legs 7 cow_nose 2
 * I want to be able to sort by all the meta keys (cow_type, cow_legs, cow_nose).
   With all I mean not all at the same time, but when I click a link for cow_type,
   cow_type should be ordered and cow_legs and cow_nose is then independent. As 
   you can se when sorting cow_legs, it is a number and when sorting on cow_type
   it is letters.
 * So here I’m stuck using the technique [http://wordpress.org/support/topic/sort-posts-by-custom-field-numeric-value?replies=12](http://wordpress.org/support/topic/sort-posts-by-custom-field-numeric-value?replies=12)
 * Because then the SQL-question should look different depending if it is a letter
   or number based custom_fields.
 * So my question is, do I have any chance to solwe this with a query_posts() statement
   or is this impossible and I most use the technique linked above?

Viewing 1 replies (of 1 total)

 *  Thread Starter [Fredriks](https://wordpress.org/support/users/fredriks/)
 * (@fredriks)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/sort-custom-fields/#post-1721543)
 * Somebody who has a clue?

Viewing 1 replies (of 1 total)

The topic ‘Sort custom fields’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [Fredriks](https://wordpress.org/support/users/fredriks/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/sort-custom-fields/#post-1721543)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
