Working with custom taxonomies

Looking around in the WP codex, it dawned on me that there’s not much yet that’s been documented about how WordPress lets us manipulate custom taxonomies. Since WP2.3, we’ve been able to create custom post types, which can have their own custom categories and custom tags. The beauty of this is that, you can divide your content into regular posts (and use them exclusively for blogging) and specialized posts that are meant for non-blog stuff.

For example, I’m working on a classified-ads site and the premium theme package I’ve chosen makes use of custom post types. It’s a wonderful theme (ClassiPress) and I love it. Classified ads appear in their own custom posts called ad listings, and are posted under ad categories. The screenshot of the site’s dashboard (see image) shows an extra menu item that says “Ads”. Dabawenyo.biz dashboard The ad listings, their categories and tags are accessible under this menu.

The ClassiPress theme (made by Appthemes.com) has lots of cool built-in features, too, such as a way for ad posters — people who submit ads to the site — to mark for-sale items as “sold”. And, when ads are marked thus, the ad page would have a “sold” tag prominently displayed on it. Problem is, I’ve put in other classified-ads sections in the mix: For Hire, For Rent and Personals. It wouldn’t be a good idea to have, say, a caterer’s services advertised under the For Hire section to be marked as “sold”, would it?

The challenge was to customize the theme’s functions so that only ads posted under the For Sale section (or under its sub-categories) would be able to have the “sold” tag. I thought WP’s native in_category() and related functions would be enough. Wrong. That particular function only works with the default taxonomy system (ie., regular categories and link categories). So, I’d like to share here how I solved it.

The next page shows how I did it.

| Page 1 Page 2 |

4 Responses

Write a comment
  1. very nice solution ! i will try it myself .thanx

    Villadecker

    villadecker 14 December 2010 at 8:51 PM Permalink
    • If you find a way to streamline the functions further, I hope you'll share it too! Thanks for reading my blog, villadecker. :)

      Blogie 14 December 2010 at 9:40 PM Permalink
  2. I tried this in my classipress 3.0.5.3 and it still shows "mark as sold" for every ad in my dashboard.

    Dennis 20 February 2011 at 1:25 PM Permalink
    • Hi Dennis. I'd have to know a bit more than the version to figure out why it's not working for you… ;)

      Blogie 22 February 2011 at 7:01 PM Permalink

Write a Comment

Commenter Gravatar