WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running a network of about 80 sites using WP multisite 3.2. I'm experiencing irregularities using switch_to_blog whith wp_insert_term.

To test this I have disabled all plugins, and am testing on a blank page so nothing else interferes. This is the sample code:

wp_insert_term( 'New Term','category');

When run from most blogs it adds the new term to the desired blog and the permalink to the new term page works.

But for a few of the blogs, when it runs it adds the term, but the link to the new term page throws a 404 error. Opening wp-admin and adding any new term through wp-admin fixes it.

Any ideas why this is happening?

share|improve this question

Hook into 'pre_insert_term', $term, $taxonomy and dump the global $blog_id; to see if you're on the right place:

function wpse_inspect_blog_id( $term, $taxonomy )
    global $blog_id;
    var_dump( $blog_id );
function wpse_hook_inspector_blog_id()
    add_filter( 'pre_insert_term', 'wpse_inspect_blog_id' );
add_action( 'init', 'wpse_hook_inspector_blog_id' );
share|improve this answer

Your Answer


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.