I’d like to build an advanced search form for a specific custom post type, having filters for the custom post types custom fields, custom taxonomies, and for a separate custom post types properties (fields and taxonomies) which will be links to the first post type using a custom relationship field.
I’ve recently started off with WPs custom post types, fields, and taxonomies, I love it so far but to make the best of it I’d like to be able to search it properly. Do I need to do it manually? If so, how?
PS. If it matters, I’m using the plugins: Advanced Custom Fields and Custom Post Type UI.
Below I’ve mocked up an example of how the filtering would look and how it might relate to the post types above.
I think something like this you would be best writing yourself.
Take a look at: http://www.catalysthomes.co.uk/homes-for-sale/
Properties are loaded into a CPT and I have my own custom search in the sidebar. Of that search its searching a number of things such as taxonomies, custom fields and ordering by date price etc.
So how do I achieve this? I submit the form to a page template and from there I deal with the post data and build a new WP_query based on the search criteria. I use sessions to store the search variables so that I can paginate the results.
WP_Query is very powerful. Take a look: http://codex.wordpress.org/Class_Reference/WP_Query
In there you can use
meta_query
to query multiple custom fields and usetax_query
to query your taxonomies, plus there is more. Below is how mine is built to give you an idea.Template File:
Raw Results
Search Results
List Layout
Just a standard WP loop to show post excerpts and info.
Try Taxonomy Picker plugin together with Relevanssi. Killer combination.
http://www.squidoo.com/taxonomy-picker-wordpress-plugin
http://wordpress.org/extend/plugins/relevanssi/
Take a look at Relevanssi plugin, it might do what you are looking for: http://wordpress.org/extend/plugins/relevanssi/
If anyone is having difficulty implementing Brady’s solution above (as I did) here’s a hint: It appears that WordPress has some problems with passing session data so you will probably have to do something extra to make it work properly. The issues are discussed here
In functions.php:
In your template:
For me installing Peter Wooster’s “Simple Session Support” plugin did the trick.