Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've created a custom post type called 'properties' with custom meta boxes of 'price' and 'rooms'.

I have a custom loop-property-archive.php to display the properties.

What I would love to have is a method to sort the properties based on the meta data from those two meta boxes. Ideally I would have a drop-down called 'sort by', with the options of 'price asc.', 'price desc.', 'rooms asc.', and 'rooms desc.'. When the user selects an option the page is re-sorted.

I can currently query by custom taxonomies, which creates a URL like: mysite.com/?post_type=properties&area=high-ridge&university=birmingham. I need to be able to filter that page or any other combination of area and university. Therefore building individual templates with custom queries is out of the question.

I tested out appending meta_key=_price&orderby=meta_value to the URL but that doesn't work. Any ideas why?

I'm open to server or client side suggestions. Server may be better because if there is pagination involved I think that would be handled better. Obviously client side has the advantage of no page refreshes though.

Thanks!

share|improve this question

1 Answer 1

This should help: http://wordpress.org/support/topic/custom-select-query-sort-by-meta-value-within-category (look for the posts from user t31os)

Also this: http://codex.wordpress.org/Template_Tags/query_posts#Passing_variables_to_query_posts

share|improve this answer
    
Thanks but I don't think those solutions are quite what I'm looking for. I need to create a query that includes the previous query (if that makes sense!). So if someone searches for a property with a university of 'birmingham' and an area of 'newtown', on that archive page I then need to be able to sort the posts while keeping the original query. Complicated, but it would be really useful! –  kdev Jul 5 '11 at 10:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.