Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create category on WPMS blog from another blog in the same network.
<?php
// current blog
$switch_from = get_current_blog_id();
// blog id we are switching to so we can create a category there
$switch_to = 2;
echo 'About to switch to '.$switch_to.' from '. $switch_from.'.';
// https://codex.wordpress.org/WPMU_Functions/switch_to_blog
switch_to_blog( $switch_to );
echo 'You switched from blog ' . $switch_from . ' to '.$switch_to;
// https://codex.wordpress.org/Function_Reference/wp_insert_term
wp_insert_term(
'monkeys', // the term
'category', // the taxonomy
array(
'description'=> 'Very fond of bananas.',
'slug' => 'monkeys'
)
);
// https://codex.wordpress.org/WPMU_Functions/restore_current_blog
restore_current_blog();
echo 'You switched back to '.get_current_blog_id().'.';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.