Support » Fixing WordPress » Dropdown to sort posts by numeric custom field

  • Been trying to figure this out and read so many ideas but I just can’t get it to work.

    I have a custom field called property_price. On category.php I want to have a dropdown menu that offers the posts to be sorted by highest or lowest price. Each post has a price assigned as a number (no £ sign).

    Firstly WP lists numbers like this:
    1, 10, 100, 2, 3
    I’ve seen this solved by altering a core file query.php but i don’t want to do that.. I’ve also read that this problem should have been solved by now but it still seems to work like that for me.

    Secondly, how to do the query_posts so that it works on a dropdown. My most recent attempt looked like this:

    <?php if (have_posts()) : ?>
         <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("meta_key=property_price&meta_compare=>=&meta_value=1&orderby=meta_value_num&order=ASC&paged=$paged"); ?>
            <?php while (have_posts()) : the_post(); ?>

    But obviously this is just a static list and I need the dropdown with options (price: ascending, and price: descending.

    Can anyone help?

  • The topic ‘Dropdown to sort posts by numeric custom field’ is closed to new replies.