Skip to content

Instantly share code, notes, and snippets.

@luetkemj
Last active August 29, 2015 14:23
Show Gist options
  • Save luetkemj/a8a0b317cb58ed5ec136 to your computer and use it in GitHub Desktop.
Save luetkemj/a8a0b317cb58ed5ec136 to your computer and use it in GitHub Desktop.
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