[wp-hackers] Creating Custom Taxonomies on the fly

Haluk Karamete halukkaramete at gmail.com
Sat Jan 29 23:33:50 UTC 2011


Here is the scenario;

Say, I have 4 categories; videos, podcasts, interviews, advanced
subjects.  As I get new content,  I tag my items under the regular
post-tags taxonomy.
With this very common scenario, I can create a tag cloud at any point
of time to see in what my subjects matters are accumulating into.

The problem with this is that I cannot break this tag cloud into
individual tag clouds that would make sense for each of these
categories.

In other words, neither I nor my visitors could easily tell what tag
cloud is available under say "advanced subjects" for example. Even
though, I got the main tag cloud available to me, there would be no
guarantees even for the top tagged item ( that's the biggest tag in
the main tag cloud) to have a matching even single post for the
advanced subjects category.

First Solution to that is to use non-hierarchical taxonomies. In that
case, surely I could have individual tag clouds. But that would have
been cumbersome as it would have involved duplicate tag entries under
various taxonomies whenever that tag item is applicable to multiple
taxonomies.

Here is an idea in its infancy, ready to take your input/feedback.

Imagine a plug in that hooks to the function that saves the post into
the wp_posts table and does the following;

check for the current post, if the currently associated categor(ies)
exist as custom taxonom(ies), and if not, create them on them on the
fly and explode currently associated tags ( from the post-tags
taxonomy ) to each and every taxonomy involved.

For the inconvenience purposes, webmaster adopts this style; just work
with categories and the built-in tags and completely rely on the plug
in that does the taxonomy and tags on the fly.

When the webmaster ads a new content, he selects the categories that
the post may belong to, and then tag the item.
say his new post deals with "videos", and "advanced stuff" categories
for example and he tags the content as tag,1 tag2 under the post-tags.

Thanks to the plug in, following happens.

Plug in checks the current tag/category associations and figures out
this particular post belongs to "videos" category and "advanced stuff"
category and it has the tags tag1 and tag2.
Based on that, plug in does the following;

check if "videos" custom taxonomy exists, if not create the "videos"
custom taxonomy and assign the tag1 and tag2 under the "videos"
taxonomy on the fly. And do the same to the other categories involved
- which in this case would be the "advanced stuff" category. So, the
plug in will also check if "advanced stuff" custom taxonomy exists,
and if not, it would create it and then assign the tag1 and tag2 under
the advanced taxonomy, again on the fly.

So, what's the benefit? Obviously, webmaster's data entry process is
fast and smooth and WP/plug in takes care of the hassle on the fly.

Most benefit will be for the users who visit the site. They will be
presented with individual tag clouds whichever category they happen to
land on.

They see the Videos, Pod Casts, Advanced Stuff and Debates categories
individually. But when they visit one of the category pages each is
showing its proper tag cloud. In fact, by some UI management, that tag
cloud may be served as sub categories under the current category.
Since the tag cloud would be organically growing, sub categories will
also grow organically - taking the hassle of creating/planning for sub
categories right off the bat.

Do you see some value in this approach? Or are there easier/smarter
ways to address the problem I'm trying to solve with less hassle?


More information about the wp-hackers mailing list