Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using WordPress mu 2.9.2 and have the same category structure on all my blogs. How do I add categories to all my blogs simultaneously? Is there a plugin that does this effectively?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You could write a script for that, here is something I wrote in Perl lately:

  1. first the sql statements to check if the term already exist and if not insert it:

the prepared statements:

my $wts    = $dbh->prepare(
"SELECT term_id FROM $tb_wp_terms WHERE name = ?")
or die "Couldn't prepare statement: " . dbh->errstr;

my $wti    = $dbh->prepare(
"INSERT INTO $tb_wp_terms
(name, slug) VALUES (?,?)")
or die "Couldn't prepare statement: " . dbh->errstr;
  1. then make the term taxonomy entry:

the prepared statements:

my $wtts    = $dbh->prepare(
"SELECT term_taxonomy_id FROM $tb_wp_term_taxonomy WHERE term_id = ? 
 AND taxonomy = '".$config{'wordpress.taxonomy_type'}."'")
 or die "Couldn't prepare statement: " . dbh->errstr;

my $wtti    = $dbh->prepare(
"INSERT INTO $tb_wp_term_taxonomy
(term_id, taxonomy, count) VALUES (?,?,1)")
or die "Couldn't prepare statement: " . dbh->errstr;

my $wtts_count    = $dbh->prepare(
"SELECT count FROM $tb_wp_term_taxonomy WHERE term_taxonomy_id = ? AND taxonomy =
   '".$config{'wordpress.taxonomy_type'}."'")
or die "Couldn't prepare statement: " . dbh->errstr;

my $wtti_count    = $dbh->prepare(
"UPDATE $tb_wp_term_taxonomy
 SET count = ?
 WHERE term_taxonomy_id = ?
 ")
or die "Couldn't prepare statement: " . dbh->errstr;

And use the queries above with some code around it (you need to check for blogs that already have some of the categories).

For MU only the blogs > 1 get a blog id in their table name:

my $tb_blogid = "";
if ( $config{'wordpress.wp_mu_blog_id'} > 1 )
{
$tb_blogid = "_" . $config{'wordpress.wp_mu_blog_id'};
}
my $tb_posts                    = $config{'wordpress.prefix'} . $tb_blogid . "_posts";
my $tb_wp_terms                 = $config{'wordpress.prefix'} . $tb_blogid . "_terms";
my $tb_wp_term_taxonomy         = $config{'wordpress.prefix'} . $tb_blogid .     
"_term_taxonomy";
my $tb_wp_terms_relationships   = $config{'wordpress.prefix'} . $tb_blogid . 
"_term_relationships";

So just loop through them.

share|improve this answer
    
yes - writing a small plugin to loop through each blog works great, thanks for the code! –  Innate Jan 14 '11 at 10:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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