Title: Order Posts based on Value
Last modified: August 20, 2016

---

# Order Posts based on Value

 *  Resolved [marques_uk](https://wordpress.org/support/users/marques_uk/)
 * (@marques_uk)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/order-posts-based-on-value/)
 * Hi,
 * I wonder if anyone can help me with a problem I’m having, I’ve been searching
   the internet for a few hours and I can’t seem to find a simple solution to order
   my posts in a specific order.
 * I’ve got this query that orders the posts based on meta values
    `<?php query_posts("
   meta_key=number&orderby=meta_value"); ?>`
 * It orders my numbers but it lists the numbers from high to low, I’d like to reverse
   this so the posts start with the smallest number?
 * Is there a simple solution?
 * Thanks in advance
    Mark

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/order-posts-based-on-value/#post-2368710)
 * Could it be that your numbers are being returned as strings? I’ve not tried it
   but would a meta-query work?
 *     ```
       $args = array(
       	'orderby' => 'meta_value',
       	'meta_query' => array(
       		array(
       			'key' => 'number',
       			'type' => 'number'
       		)
       	)
        );
       query_posts($args);
       ```
   
 *  Thread Starter [marques_uk](https://wordpress.org/support/users/marques_uk/)
 * (@marques_uk)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/order-posts-based-on-value/#post-2368805)
 * Hi esmi,
 * No that doesn’t seem to work either. It is querying the post as if you change
   the key name to one that doesn’t exist no posts are displayed.
 * The above code orders my numbers as 20.00, 40.00, 30.00?
 * Any other suggestions?
 * Thanks
    Mark
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/order-posts-based-on-value/#post-2368807)
 * `<?php query_posts("meta_key=number&orderby=meta_value_num"); ?>`
 *  Thread Starter [marques_uk](https://wordpress.org/support/users/marques_uk/)
 * (@marques_uk)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/order-posts-based-on-value/#post-2368809)
 * That orders them 40.00, 30.00, 20.00. Need to reverse it somehow? 🙂
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/order-posts-based-on-value/#post-2368810)
 * try:
 *     ```
       <?php query_posts("meta_key=number&orderby=meta_value_num&order=ASC"); ?>
       ```
   
 *  Thread Starter [marques_uk](https://wordpress.org/support/users/marques_uk/)
 * (@marques_uk)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/order-posts-based-on-value/#post-2368814)
 * That line of code worked perfect, thank you keesiemeijer! Thanks for your help
   as well esmi.
 * I have another ordering problem that you might be able to help me with?
 * I have the code
    `<?php wp_list_pages('title_li='); ?>` that displays the navigation
   list of pages, however, because the home page gets added first, it always comes
   last. I know you could just add the home page last but I’d like to add future
   pages to my website and I won’t want to keep removing the home page and re-adding
   so it comes first.
 * So at the moment I get Contact Testimonials Services Home.
 * How can I adjust the code so the page Home always come first in the list? i’m
   not to bothered about the order of the other pages.
 * I hope that makes sense?
 * Thanks
    Mark
 *  Thread Starter [marques_uk](https://wordpress.org/support/users/marques_uk/)
 * (@marques_uk)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/order-posts-based-on-value/#post-2368826)
 * Oh it’s OK, I’ll just use the Page Attributes and make sure that Home is always
   0.
 * Thanks anyway
    Mark

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

The topic ‘Order Posts based on Value’ is closed to new replies.

## Tags

 * [meta_key](https://wordpress.org/support/topic-tag/meta_key/)
 * [meta_value)](https://wordpress.org/support/topic-tag/meta_value/)
 * [orderby](https://wordpress.org/support/topic-tag/orderby/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 3 participants
 * Last reply from: [marques_uk](https://wordpress.org/support/users/marques_uk/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/order-posts-based-on-value/#post-2368826)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
