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

12 Comments

  1. Cretch
    Posted 27 May 2008 at 20:02 | Permalink

    I think you should put the SQL query to create the tables needed. Would be very useful

  2. Posted 27 May 2008 at 22:26 | Permalink

    @Cretch: The plugin will create the new tables itself, no need to do that. At least it should, but if that doesn’t work, please do let me know.

  3. Cretch
    Posted 27 May 2008 at 22:41 | Permalink

    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?

  4. Posted 27 May 2008 at 23:00 | Permalink

    @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.

  5. Posted 13 Jun 2008 at 20:29 | Permalink

    it doesn’t look like the tables were created. I’m not seeing them. i’ll glance thru the code and try to create them manually.

  6. Justin
    Posted 17 Jun 2008 at 01:48 | Permalink

    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

  7. Posted 17 Jun 2008 at 11:45 | Permalink

    @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?

  8. Chris
    Posted 19 Jul 2008 at 01:14 | Permalink

    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.

  9. Posted 28 Jul 2008 at 15:53 | Permalink

    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.

  10. Chris L
    Posted 27 Sep 2008 at 07:46 | Permalink

    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…

  11. Posted 27 Sep 2008 at 12:58 | Permalink

    @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! :)

  12. Deryk
    Posted 04 Oct 2008 at 09:23 | Permalink

    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.

One Trackback

  1. [...] published the Real Global Terms and the SH Global Posts plugins today. It’s code I’ve had running for ages and have [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Categories

  • History