Real Global Terms

Please Note: This is a WordPress MU plugin, do not install it on a standalone version of WordPress. WPMU and this plugin require some PHP knowledge. It’s not intended for end users. You have been warned! 🙂

Intro

The sitecategories table in WPMU is somewhat broken. It’s a left over from the upgrade to the new term / taxonomy structure introduced in WordPress 2.2. This plugin removes the filter that keeps the sitecategories table up to date. Instead, it creates two new tables ‘site_terms’ and ‘site_term_taxonomy’.

Then it populates these tables every time a new term or term_taxonomy is created, and keeps the IDs in sync on each individual blog. The end result is that you have a global term / term_taxonomy system.

This is fairly useless in itself. However, it provides the foundation for the SH Global Posts plugin which provides global categories, global tags, global search, etc.

Core code

This plugin relies on a core code change. I’ve requested that this be included in WP core, but as at May 2008 that hasn’t been done. So, you will need to edit the file manually.

You can download the patch here. Or, you can edit the files manually. Look for this line in wp-includes/taxonomy.php:

    $term_id = apply_filters('term_id_filter', $term_id, $tt_id);

Then immediately following it, add this line:

    $tt_id = apply_filters('term_taxonomy_id_filter', $tt_id, $term_id);

So the end result will be this:

    $term_id = apply_filters('term_id_filter', $term_id, $tt_id);
    $tt_id = apply_filters('term_taxonomy_id_filter', $tt_id, $term_id);

As at revision 1260 (27 May 2008) this code appears twice in the wp-includes/taxonomy.php file, at lines 1228 and 1484. The quickest way to find these lines is search the code for “term_id_filter”.

After Install

When you install the plugin, it will check if it has already been installed (using a site option) and then globalise all your existing terms / term_taxonomies. This could take some time and will happen on the first page request (anywhere on the site) immediately after install. So I’d suggest installing when the site is quiet and hitting a page immediately.

MU Plugins

This plugin must be installed for all blogs on your site, so it must be in the ‘wp-content/mu-plugins’ directory. If you install it in the ‘wp-content/plugins’ directory the world may very well end. 🙂

Support

I’m happy to answer developer questions here and there, but I can’t provide end user support for this plugin. If you can’t read the code and understand what it does, I’d suggest avoid using the plugin. If you ask me very nicely and promise to send me chocolate cake, I might be able to help. But it’s strictly at your own risk. Please post any questions in the comments on this page.

Download

If you have made it this far and still want to proceed, please go ahead and download the code here. I’d strongly recommend you subscribe to this feed to be kept informed about updates to the plugin.

Gratitude

This plugin was created as part of my work with SmartHippo. If you’d like to show gratitude, please register with SmartHippo and post a rate.

Changelog

0.1.1 – Updated plugin description
0.1 – First public release

13 thoughts on “Real Global Terms”

  1. The plugin didn’t change my tables. And as stated in real-global-terms.php: “Currently does not create the global term tables, they must be created manually.”

    Did I miss some point?

  2. @Cretch: Ignore that in the plugin description, that’s out of date! I’ve updated it, the latest code does the same thing, but has an updated description and version no.

  3. I ran a sql query and created the tables from the global_terms.php. I also edited the taxonomy.php per your instructions. But I put the sh_global_posts.php in the mu_plugin floder all categories dissapear from wpmu admin. When I try to create a new category from wpmy admin it states “undefined error.

    If I remove the sh_global_posts.php the original categories are still there and there is no error but the site seems unchanged from the original mu (no global changes).

    I am using wpmu 1.5.1
    php 4.4.8
    mysql 5.0,51a

    Any help soon will be greatly appreciated

  4. @Justin: Sorry to hear about your problems. I’m not sure what’s going on to be honest. Has the initial import run? Do you see any data in the global tables? Perhaps if you have a lot of data it’s causing a PHP timeout or something. Anything in the PHP error logs?

  5. Urrgh, timeout. ok, forget all of that. PHP5.

    Jason, I feel your pain. Managed to create tables using:

    Clicked on a tag and poof! Categories listed (still no content).

    err log:

    `WordPress database error Unknown column ‘tt.count’ in ‘where clause’ for query SELECT t.*, tt.* FROM wp_site_terms AS t INNER JOIN wp_site_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN (‘post_tag’) AND tt.count > 0 ORDER BY tt.count DESC LIMIT 45 made by get_terms`

    There also appears to have been a change in the cat_id as my template supresses certain cat_id, no more… I’ll play with that later. Hopefully that value is static.

  6. This plugin hasn’t been updated to the latest version of WPMU yet. I’m waiting for some stuff to happen internally at work before that goes through. It should be soon though, then I’ll post the updated code. Although this may be superseded by Donncha’s plugin.

  7. Do you still plan to update this? I like Donncha’s plugin OK, but it doesn’t ahve the ability to integrate existing posts and terms like yours does, which is important for me…

  8. @Chris L: Yes, I will have to update the plugin. I’m about to roll out the latest WPMU onto our production site, so I’ll have to fix any issues then. 🙂

    I should have an update ready in the next 2-4 weeks I’d guess. But feel free to keep hassling me by email! 🙂

  9. I’m really looking forward to the update of this plugin. I hope I can offer support for it after I install and understand it.

Leave a Reply

Your email address will not be published. Required fields are marked *