[resolved] wp insert term and Multisite (4 posts)

  1. valuser
    Posted 3 years ago #

    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

  2. Sandra l***
    Posted 3 years ago #

    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: http://codex.wordpress.org/WPMU_Functions/switch_to_blog

    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.

  3. valuser
    Posted 3 years ago #

    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.

  4. valuser
    Posted 3 years ago #

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


Topic Closed

This topic has been closed to new replies.

About this Topic