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 want to create one extra table filed if it is multisite's main blog (While plugin activation).

I mean like this

if (main blog) {
  execute this sql;
}
else {
  execute this sql
}

PS: This is the code for "execute this sql".

If child blog:

$sql = "CREATE TABLE tablename (
                  id bigint(20) NOT NULL AUTO_INCREMENT,
                  uid bigint(20) NOT NULL,
                  type VARCHAR(256) NOT NULL,
                  data TEXT NOT NULL,
                  credits bigint(20) NOT NULL,
                  timestamp bigint(20) NOT NULL,
                  UNIQUE KEY id (id)
                );";

If main blog:

$sql = "CREATE TABLE tablename (
              id bigint(20) NOT NULL AUTO_INCREMENT,
              uid bigint(20) NOT NULL,
              type VARCHAR(256) NOT NULL,
              data TEXT NOT NULL,
              credits bigint(20) NOT NULL,
                      globalcredits bigint(20) NOT NULL,
              timestamp bigint(20) NOT NULL,
              UNIQUE KEY id (id)
            );";

Can anyone help me?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You can use is_main_site conditional tag like this:

if (is_main_site()) {
  execute this sql;
}
else {
  execute this sql
}
share|improve this answer
    
Thankyou....... :) –  Giri Jan 27 '12 at 18:27

Check for the $blogid. Main site is 1.

global $wpdb;

$mainblog = $wpdb->blogid;

if ($mainblog === 1) {
   execute this sql;
}
else {
    execute this sql
}
share|improve this answer
    
Thankyou....... :) –  Giri Jan 27 '12 at 18:27

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.