I want to give the user the ability to order posts by post date/alphabetically either on ASC or DESC order through a
select input on an archive page.
The easy way would be to show two inputs on the front end: one controlling the
order_by parameter, and other controlling the
But it would be a lot better if it were just one select input field with four options:
- Alphabetical A-Z
- Alphabetical Z-A
I tried cheating, using
& inside each option's value, but it gets automatically escaped on the URL.
<form action=""> <select name="orderby" id=""> <option value="post_date&order=DESC">Latest</option> <option value="post_date&order=ASC">Oldest</option> <option value="post_title&order=ASC">Alphabetical A-Z</option> <option value="post_title&order=DESC">Alphabetical A-Z</option> </select> <button>Filter</button> </form>
This code gives me a URL like this: