How do I sort posts by a custom field dynamically? Plugin?
-
I’m working on a car dealership website and I managed to get the posts to display in numeric order by a custom field of “price” either ASC or DESC. The problem is I add this code to the header.php template, but I can only display them in order once depending if I choose ASC or DESC:
<?php query_posts($query_string. '&orderby=meta_value&meta_key=price&order=DESC' ); ?>
I want to make a “Price” button that when people click on it will toggle the order of the posts based on the price custom field. I know this is hard since it would be mixing preloaded php with dynamic content, but maybe someone knows of a way to accomplish this possibly with a plugin. Thanks in advance.
- The topic ‘How do I sort posts by a custom field dynamically? Plugin?’ is closed to new replies.