I have a custom post type “Properties”.
These properties posts are being listed out on page “Properties For Let”.
Each property post has various custom meta including price, and number of bedrooms.
The properties will initially be listed in the order defined by the original wp query I set.
However at the top of the page I wish to have links that upon click will sort the posts by Price, Date Added and Number Of Bedrooms.
What is the best practice for doing this? I have seen people advise on addin query strings to URLs etc but would like some solid advice
Thanks in advance for any help
John
The function
add_query_arg
adds or replaces ‘GET’ parameters in a given (or the current) url.For instance, suppose someone is viewing the page:
http://www.example.com?order=ASC&orderby=meta_value_num&meta_key=price
(viewing properties in price order). Then the url
Would give you
http://www.example.com?order=ASC&orderby=meta_value_num&meta_key=bedrooms
(the url to order properties by number of bedrooms).
E.g:
I have explained a method over here. You’ll need to tweak the code a little bit.