Support » Networking WordPress » wp insert term and Multisite

  • Resolved valuser


    In multisite can you insert a term into another blog with wp_insert_term.

    for example
    <?php wp_xx_insert_term($var, 'category'); ?>

    where xx is the blog id of the blog to receive the category and $var is the category to be included ???

    or how best go go about this i.e if a category is created in blog a i want that category to be created in blog b

    help very much appreciated

Viewing 3 replies - 1 through 3 (of 3 total)
  • I think you’d have to switch blog before you can wp_insert_term().

    To switch blogs, one uses switch_to_blog($xx) where $xx is the id of the other blog. You can read about it here:

    Warning: I’ve only ever done that to pull information from a specific site. Things might come in your way, when trying to insert data via this method. I’d say, give it a try.

    Many thanks @sandra l***.

    Did try that but was unable to continue as the hook i was using was ‘groups_created_group’ in the group formation panel of buddypress and it stopped the process before restore blog came in to play.

    However i am looking at a mysql route and appear to have found a kind of “round the houses” solution

    $txx = $wpdb->get_var("SELECT * FROMwp_xx_terms` ORDER BY term_id DESC”);

    $xp = 1;

    $tid = $txx + $xp;

    $wpdb->insert(wp_xx_terms, array (‘term_id’=> NULL, ‘name’=> $xgroup, ‘slug’=> $slug, ‘term_group’=> ‘0’));

    $wpdb->insert(wp_xx_term_taxonomy, array (‘term_taxonomy_id’=> NULL,’term_id’=> $tid, ‘taxonomy’=> ‘category’, ‘description’=> ‘community group’, ‘parent’=> ‘0’,’count’=> ‘0’,));`

    so I am marking this as resolved.

    Some of the single/back quotes are missing in the above e.g. on wp_xx_terms.


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp insert term and Multisite’ is closed to new replies.