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.