WordPress Experts: Getting Slug by Single_Cat_Title

An interesting problem that I came across in a recent project. The client needed a custom post taxonomy set to a gallery of choices on a featured section of their website. First we needed to add custom post types and category images plugins. Iterating through the taxonomy was a cinch but at one point I noticed that a few categories were not linking correctly. This is because we weren’t using the taxonomy’s slug but rather the name. After some searching we found this great little workaround to nail down the proper link. Slugs to the rescue!


 $cat = get_term_by('name', single_cat_title('',false), 'category');

 echo $cat->slug; 

 

http://codex.wordpress.org/Function_Reference/get_term_by

Perfect. Custom post types is a powerful tool but we’ve found a lot of weakness in terms of developing relationships between custom posts. Primarily when using CRUD – developing robust database relationships with WordPress is kind of a pain, not really there yet to replace the other options out there. I think this is because too many plugins and toolsets are gearing toward the idea of “no programming needed”  being a good selling point. Personally, it seems that just making programming easier would be the better option, rather than making a comprehensive alternative to programming. If you don’t know how to program, should you be programming at all?