There are only certain times where it’s best to create your own function to reference it, and that’s when you want to remove that filter or action later.

OK, so what’s the big deal about lambdas? Here’s a scenario where it really stood out to me that this would be what I wanted to do. I was working on a project where I needed to add filters for the custom taxonomies in a custom post type in the WordPress admin. There are 2 hooks necessary to 1) create the drop down, and 2) to filter the actual query to show the results. We currently have 4 custom taxonomies, so that would be 8 functions, each 2 repeated over and over for the 4 taxonomies. Here’s a solution that creates a reusable function where you pass in the $post_type and $taxonomy slug. To my knowledge, all you need is to be running PHP 5.3 or newer on your server.

Share story

TJ Nevis

Expert at knowing a little bit about everything - or so I like to think. Husband, business owner, web developer, car enthusiast, animal lover, tinkerer. I run a web development/technology company, NevisTechnology.com where I'm living my dream. Need hosting services, a website, blog, Blogger to WordPress conversion or an e-commerce store?Let's talk!