Title: Sort posts by custom fields value using dropdown menu.
Last modified: August 22, 2016

---

# Sort posts by custom fields value using dropdown menu.

 *  [Melanie van Oers](https://wordpress.org/support/users/melanie-van-oers/)
 * (@melanie-van-oers)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/sort-posts-by-custom-fields-value-using-dropdown-menu/)
 * I’m trying to sort my posts by a custom field value, called price. Only using
   numbers in the custom field value. I want that the visitors of the website can
   sort the posts on price by using a dropdown. I searched for a plugin, but couldn’t
   found that. Now u found the code below:
 *     ```
       <?php
         $order = "&order=DESC";
         if ($_POST['select'] == 'tag') { $order = "&tag=mytag";  }
         if ($_POST['select'] == 'title') { $order = "&order=ASC&orderby=title";  }
         if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
         if ($_POST['select'] == 'oldest') { $order = "&order=ASC";  }
         if ($_POST['select'] == 'mcommented') { $order = "&order=DESC&orderby=comment_count";  }
         if ($_POST['select'] == 'lcommented') { $order = "&order=ASC&orderby=comment_count";  }
         if ($_POST['select'] == 'prijs') { $order = "&order=ASC&orderby=meta_value_num";  }
       ?>
   
       <form method="post" id="order">
         Sort reviews by:
         <select name="select" onchange='this.form.submit()'>
           <option value="tag"<?php selected( $_POST['select'],'tag', 1 ); ?>>Tag</option>
           <option value="title"<?php selected( $_POST['select'],'title', 1 ); ?>>Title</option>
           <option value="newest"<?php selected( $_POST['select'],'newest', 1 ); ?>>Newest</option>
           <option value="oldest"<?php selected( $_POST['select'], 'oldest', 1 ); ?>>Oldest</option>
           <option value="mcommented"<?php selected( $_POST['select'],'mcommented', 1 ); ?>>Most commented</option>
           <option value="lcommented"<?php selected( $_POST['select'],'lcommented' , 1 ); ?>>least commented</option>
           <option value="prijs"<?php selected( $_POST['select'],'prijs' , 1 ); ?>>prijs</option>
         </select>
       </form>
   
       <?php query_posts($query_string . $order); ?>
       ```
   
 * But the last selection option ‘prijs’ is not working.
 * Can somebody help me? Or do you need more information?
 * Sorry for my English if it’s not totaly correct.

Viewing 1 replies (of 1 total)

 *  Thread Starter [Melanie van Oers](https://wordpress.org/support/users/melanie-van-oers/)
 * (@melanie-van-oers)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/sort-posts-by-custom-fields-value-using-dropdown-menu/#post-5408522)
 * What i mean is to see on: [http://highendaudio.nl/html/content/index.asp?id=64&show=3&list=53](http://highendaudio.nl/html/content/index.asp?id=64&show=3&list=53).

Viewing 1 replies (of 1 total)

The topic ‘Sort posts by custom fields value using dropdown menu.’ is closed to 
new replies.

## Tags

 * [sort posts](https://wordpress.org/support/topic-tag/sort-posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Melanie van Oers](https://wordpress.org/support/users/melanie-van-oers/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/sort-posts-by-custom-fields-value-using-dropdown-menu/#post-5408522)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
