There are numerous high quality WordPress themes that provide website visitors the ability to query custom post types via multiple drop-down menus. Two that quickly come to mind are targeted towards those that require a real estate solution. The AgentPress theme developed by StudioPress and the deCorum theme developed by ThemeShift are excellent examples. Both themes allow visitors to select from multiple taxonomy terms in order to produce a desired result and both themes serve as a great starting point for creating high quality real estate websites.
What if you wanted to build a custom business directory, a classifieds site, a job listings site or one of the many other sites that could benefit from using custom post types? The themes mentioned above would require a fair amount of code wrangling. I know, because I did just that with AgentPress by hacking both the theme and its companion plugin. I actually ended up with pretty good results when I transformed AgentPress into a business directory however I found myself needing more flexibility.
Enter the Easy Content Types Plugin for WordPress developed by Pippin’s Plugins. I’ve used the plugin for less than two weeks but it has quickly become one of my favorite WordPress plugins. Easy Content Types provides a very intuitive interface for creating custom post types, taxonomies, custom fields and meta boxes. It also serves as a great learning tool because it has the ability to export the code created by the interface for use on sites without the plugin. This is one brilliant plugin!
Speaking of brilliant plugins, those that follow me on Twitter know that I absolutely love the Gravity Forms plugin by Rocket Genius. I started using Gravity Forms back in 2009. Trust me, if you develop WordPress sites, you cannot afford to be without this plugin. Recently I was searching for a code snippet or plugin that would function much like the aforementioned AgentPress or deCore theme and allow me to query the custom post types created by the Easy Content Types plugin. After much searching it struck me that Gravity Forms just might be the answer.
I’ve just started experimenting with a solution and in the end there may be a better approach but I thought I would share where I’m at so far since a few people have asked. Let’s assume that you have installed the Easy Content Types Plugin, created a custom post type named “listings” and you have created the taxonomies of “city” and “industry”. Create a few listings and enter some terms into your new taxonomies. Now create a new form using the Gravity Forms plugin. I named my form “Search Form”. I created 4 “Standard Fields”; City, Industry, Order By and Sort Order. Make sure you click the Advanced tab on each field and type the appropriate lowercase version (example: city, industry, orderby & order) into the Admin Label field. Also, the drop down field Choices (taxonomy terms for fields City & Industry) have the ability to use a Label and a Value. Make sure you click the “enable values” checkbox. The Label is seen by the website visitor, the Value is what is actually passed by the form. In my example, the Industry drop-down field has Choice Labels of Web Design, Advertising & SEO but the Choice Values are (web-design, advertising & seo). The Order By drop-down has Labels of Title, Date & Random but the Values are (title, date, rand). Making sense?
Next, go to the Form Settings and click the Confirmation tab.
Select the “Redirect” radio button. I entered: http://themecraft.com/demo/dev/? into the blank field.
Select the “Pass Field Data Via Query String” checkbox. I entered: city={city:1:value}&industry={Industry:2:value}&orderby={orderby:3:value}&order={order:4:value}
Save your form and place the form shortcode into the page of your choice: This is my result thus far. It needs some styling but give it a try: http://themecraft.com/demo/dev/?page_id=1073
This is a work in progress and may not be the best solution for you. Keep in mind that the form will store the field selections when a query is performed. I see that as a plus since it will allow me to study the search habits of my visitors and learn their location based on the IP logged in the database. I’ll continue experimenting with the idea and post additional findings. Cheers.