0

I have a pretty complex wordpress-site for travelling. There's an "archive-hotels.php", a template for the custom-post-type "Hotels". Inside the CPT is a taxonomy called "City", so we can do this: domain.com/hotels/city. Works perfectly. Now there's a filter on the site, which should filter the shown posts by stuff that the author has added over custom fields (Advanced Custom Fields Plugin) like "Features" or "Price Range".

Now I'm not sure how to filter that query. With PHP? jQuery (there shouldnt be too much posts in hotels/city/)? or Ajax to work that dataload, which will be after years of publishing?

Domain www.business-travelling.de/hotels/hamburg

1
  • So when I search for .../hotels/hamburg?features=sea-face, the result should contain only the hotels in Hamburg which face the sea? Commented Apr 18, 2012 at 9:38

1 Answer 1

1

The permalink structure you've described above e.g..../hotels/hamburg/features/sea-face isn't really something that could be achieved by using custom fields. You would be better off creating a new taxonomy called 'features' and populating it with terms like 'sea-facing' and any others.

In order to do queries for multiple taxonomies I would recommend the excellent Query Multiple Taxonomies plugin by Scribu. This plugin will let your users build searches that span across more than one taxonomy e.g. city AND feature.

You could either use the filter widget that comes with the plugin or build your own if that doesn't quite cut it. Think in the long run this will prove simpler than messing around with more complex ajax requests or complex wordpress queries looking for combinations of custom fields.

8
  • This looks pretty nice! Thank you! I don't need a fancy and pretty domain for this! I just want to filter the current query by some custom-field-values. Just like "I just want the user to visit hotels/berlin, click on a few arguments "Whirlpool, WiFi and Breakfast", press "Filter" and a filtered list of posts appear. If this works without Ajax and jQuery, it would be perfect too!"
    – juliusk
    Commented Apr 18, 2012 at 9:56
  • To be honest using a custom taxonomy for the features will not only be quicker and easier for you to implement (using the above plugin for filtering) but it will be easier for your client/you to administer in the wordpress backend - e.g. they just have to tick a few boxes in a custom taxonomy panel as opposed to adding in any custom fields.
    – FourStacks
    Commented Apr 18, 2012 at 10:01
  • Ok I get it. I will shoot for taxonomies. Important is: The new query has to include the current taxonomy, you're in, so you don't get hotels from other towns.
    – juliusk
    Commented Apr 18, 2012 at 10:06
  • Yep, it can handle that no problem. Just bear in mind that you don't have to stick to using the widget that comes with the plugin for filtering - you can build your own if understand how the multiple queries are built.
    – FourStacks
    Commented Apr 18, 2012 at 10:11
  • Yeah Ive implemented it. Awesome to work with. My one last problem: I had to rewrite my taxonomy-urls like this: /custom-post-type/taxonomy/. So your domains with "?taxonomy=XY" doesnt work :(
    – juliusk
    Commented Apr 18, 2012 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.