Ajax Category Chain Selects

A shortcode for using Category Ajax Chain Selects


I was recently working on a project where I wanted to be able to quickly return a list of products based on the categories within a custom post type.

The idea is that the user could use drop-downs to drill-down in two category levels and return all of the products in the second tier category.

Category Ajax Chain Selects was the perfect solution to my needs. Using Ajax meant that users wouldn’t have to differentiate between two levels of categories in a single drop-down or endure a new page load just to get the second list of categories.

However, by default, the plugin only comes with a PHP function, so you need to edit your theme files to use it on your site.

I found this quite restrictive for my needs, so I built a shortcode for the function that allows you to display the chain selects anywhere you want, including on a post, page or sidebar widget.

The following shortcode has all of the parameters that the PHP function does. These are the parameters that are available:

  • tax – the taxonomy you’re trying to target
  • level – how many category levels deep you want to search
  • titles – the title in the drop-down for each category level, separated by a comma
  • labels – the label above each drop-down, separated by a comma
  • btn_text – the text to put in the “submit” button
  • exclude – the ID of any category you wish to exclude
  • count – whether to show how many posts in each category

If you drop that snippet into your functionality plugin, you’ll be able to put your chain selects anywhere you can put a shortcode.

Categories: Code & Snippets, Plugins | Permalink

What next?

Hire me

If you couldn't quite manage this yourself, find it too intimidating, or just don't have the time to do it, you can always hire Dave to do it. Please get in touch so that we can discuss your needs.

Leave a comment

If you have a question, update, or comment about the tutorial, please leave a comment. I try and respond to every comment, though it may take a few days, so please check back soon.

Let a WordPress Expert help you

Do you want to try this, but feel like you need a helping hand, in case something goes wrong? My service, The WP Butler, gives you access to WordPress expertise whenever you need it. Better yet, I'll keep your site backed up, updated and secure, so that you don't have to worry about it. It's all part of the service. Use coupon DIWW and save 15% on all plans.

Visit The WP Butler


Dave has been tinkering with WordPress for many years, and he now shares his WordPress knowledge here on Do It WIth WordPress to help others realise its impressive power. He can also be hired to help with your WordPress needs. Dave, who is British, is married to his best friend, Marti, with whom he has a beautiful daughter, Ellie. When he's not dabbling with WordPress, he's probably eating Triscuits or hummus, watching an indie film or British TV show, spending time with friends or family, or exploring the world.

Leave a Reply