• Resolved marques_uk

    (@marques_uk)


    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)
  • 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

    (@marques_uk)

    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

    <?php query_posts("meta_key=number&orderby=meta_value_num"); ?>

    Thread Starter marques_uk

    (@marques_uk)

    That orders them 40.00, 30.00, 20.00. Need to reverse it somehow? ??

    Moderator keesiemeijer

    (@keesiemeijer)

    try:

    <?php query_posts("meta_key=number&orderby=meta_value_num&order=ASC"); ?>

    Thread Starter marques_uk

    (@marques_uk)

    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

    (@marques_uk)

    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.