I have a method already of doing this but I know it can be done better and would love an opportunity to discuss with you all to see how you would do this.
So giving more info on what I mean:
Lets say I have a custom post type called properties. Each property has a title (property name), post content (the property description), a number of custom meta fields storing price, bathrooms and bedrooms and a custom taxonomy storing the property location area.
The above is a cut down but I wanted to keep it simple for our discussion.
Now I can set-up the CPT using `archive => true` and set the rewrite `slug => ‘properties’` and that will allow me to navigate to `/properties` and see 10 of the latest posts (default WordPress behaviour). How do I now build my search that allows a user to:
- Order the properties by date ASC/DESC
- Order the properties by price ASC/DESC
- Order the properties by name ASC/DESC
- Filter the properties by price range E.G. £100,000 – £250,000
- Filter the properties by bathroom/bedroom range
- Filter the properties by area
The results should always show on the same archive page `/properties` and the users search must be maintained between page loads so that pagination works (using sessions).
The optimal solution I would say would be to alter the main archive query using the action `pre_get_posts`, remember my talk on You Don’t Know Query?
However looking for some really clever ways of achieving this.
If this topic gets picked for wp-hooked I will code up the CPT, meta boxes to capture property data, the custom taxonomy, the property archive page with layout and fill with sample data. The rest of the functionality will be then open to the group.
Thank you for reading.