Id like to build a search form for a specific custom post type (vehicle) and have filters for that custom posts type’s custom meta fields (price, age) and custom taxonomies (make). This will totally replace the sites search and be the only search available so I was going to use search.php within my custom template.
I’ve like the search to look something like:
Search our vehicles
Make (select box full of all the custom taxonomies – Audi, BMW etc).
Model (normal input field for people to type whatever in).
Prices over (select box with prices starting at 1000)
Age (select box with options such as under 1 year, under 3 years, under 5 years, under 10 years).
I’m new to custom fields and dont really know where to start (I’ve found a few examples on Google but none do exactly what I’m aiming for). I didnt really want to use a plugin either. I’m guessing within search.php I grab the data passed from the form and use it to build $args up to pass to WP_Query?
Could someone point me in the right direction please? Thanks in advance
If you want to extend your query, you should extend it through the
pre_get_posts
-filter. Then just do a “Custom Field” or meta query.Hereâs the code. You can change
$post_type
and$custom_fields
according to your needs.