Title: Sorting by meta_value issue
Last modified: August 20, 2016

---

# Sorting by meta_value issue

 *  [sheep630](https://wordpress.org/support/users/sheep630/)
 * (@sheep630)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/sorting-by-meta_value-issue/)
 * `$sqlsort = "select ID from wp_posts left join wp_postmeta on wp_postmeta.`post_id`
   =wp_posts.`ID`left join wp_term_relationships on wp_term_relationships.`Object_ID`
   =wp_posts.`ID`left join wp_term_taxonomy on wp_term_taxonomy.`term_taxonomy_id`
   = wp_term_relationships.`term_taxonomy_id`left join wp_terms on wp_terms.`term_id`
   = wp_term_taxonomy.`term_id`where`ID` in (“.$rxt.”) and meta_key=’price_value’
   group by ID order by meta_value;”;
 * //echo $sqlsort.”<BR>”;
    $ressort = mysql_query($sqlsort);`
 * The price sorting by meta_value is not corret.
    output order become (1000, 2050,
   200, 300)
 * I tried to replace the meta_value with meta_value_num, but an error message comes
   up. Can any one please suggest how to solve this issue.
    Thanks in advance!

Viewing 1 replies (of 1 total)

 *  [gaurabmani](https://wordpress.org/support/users/gaurabmani/)
 * (@gaurabmani)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/sorting-by-meta_value-issue/#post-2608988)
 * you can grab the datas in an array and numerically sort it , then it will be 
   arranged in the correct format.
 * while($result = mysql_fetch_array($ressort)) {
    $meta_values[] = $result[‘price’];}
   sort($meta_values, SORT_NUMERIC); echo ‘
 *     ```
       ';
       print_r($n);
       echo '
       ```
   
 *     ```
       ';
   
       Is that one what you are looking for?
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Sorting by meta_value issue’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [gaurabmani](https://wordpress.org/support/users/gaurabmani/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/sorting-by-meta_value-issue/#post-2608988)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
