1

When a site gets to a certain scale, storing categories on a per-blog basis starts to get a little messy. Assuming someone would want all WPMU blogs to share a single set of categories, how might one go about that? My gut it so store a set of "cannonical" categories in the root blog. Is there a more elegant or standardized solution?

4 Answers 4

1

A more elegant solution would be to create a MU (must use) plug-in and drop it on the network. This plug-in would check (per-site) if the categories exist and, if not, add them as appropriate.

Here's some untested example code:

<?php
$default_categories = array(
    'my_first_cat',
    'my_second_cat',
    'my_third_cat'
);

foreach($default_categories as $cat) {
    if( get_cat_ID( $cat ) != 0 ) continue;

    wp_insert_term( $cat, 'category' );
}

This should loop through your list of categories and attempt to fetch the ID of each. If the category doesn't exist, get_cat_ID() will return "0" so you know to insert the category. This code won't set the slug, description, parent, etc ... I leave that as an exercise for you to complete.

1

Note: I'm assuming you want the categories to only be stored in one place...

If it was me and I had to do that I'd make an mu-plugin that hooks into the taxonomy insert/update/edit methods.

I'd create a new set of tables copied from the existing taxonomy tables for the parent site (just in case), with an additional field to indicate which site a post_id belongs to. The plugin would then be used to remap the name of the taxonomies table to our new site-wide one.

You'd then need a filter on all db queries to the taxonomical relationships to make them match the current site's id.

You'd also need to remove people's privileges to add/remove categories unless you're a glutton for punishment.

In short (and IMO) it would be a lot messier and a lot more restrictive to your users to have a single set of categories shared between sites. You may as well have one site with multiple authors.

1
  • I think trying to tackle this filtering at the query-level is a bad idea. For me it's much easier to just filter or hook existing functionality like the save_post action.
    – editor
    Commented Jan 11, 2011 at 19:27
1

Not sure if this solves your question, but perhaps my plugin bbAggregate addresses your requirements? It allows you to create 'streams' of content from multiple blogs in a multisite WordPress install and aggregate them onto a page. It's my replacement for Global Terms ;)

Have a look at the plugin: http://wordpress.org/extend/plugins/bbaggregate/

Read this article about it: www.roytanck.com/2010/09/30/bbaggregate-lets-you-mix-and-match-wordpress-content/

Feel free to contact me if you have any questions and/or remarks related to this plugin,

0

Hi @editor:

Your question caused me to ponder many issues so I felt that the hackers list might be a good place to ask. Here's the start of the thread; you might find it enlightening:

1
  • Thanks. We've actually worked this one out, so I know it's possible even if a bit obtuse. (Interestingly, I think someone told me that back in the day WordPress stored its categories in a single table rather than per-blog, so I suspect this problem arose shortly after that schema was dumped.)
    – editor
    Commented Jan 11, 2011 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.