Title: wp_insert_term issue
Last modified: August 20, 2016

---

# wp_insert_term issue

 *  [ErikStromme](https://wordpress.org/support/users/erikstromme/)
 * (@erikstromme)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/wp_insert_term-issue/)
 * Hi all, I’ve been pulling my hair out for two weeks on this one, any help would
   be really appreciated.
 * I’m using WP multisite 3.2.
 * On the site front end I have a tool that uses wp_insert_term to add a new category
   to any one of the mutlisite blogs (Im using switch_to_blog() in case that matters).
 * I’m then calling wp_set_object_terms() to add a post to the new category created.
 * Both these work fine, the new category gets created and the post gets switched
   to that category.
 * **The Problem:**
 * The permalink for the post in the new category throws a 404 error.
    The post 
   does not get added to the Post Count for the new category.
 * Both these problems can be resolved by:
 *  A) Go to wp-admin -> settings -> permalinks and save permalinks
    B) Go to wp-
   admin -> posts -> categories -> and add any other category
 * The above two solutions won’t work for me as I can’t manually do this everytime
   a user uses the tool we built.
 * **What we have tried:**
 * function flush_permalinks() {
    global $wp_rewrite; $wp_rewrite->set_permalink_structure(‘/%
   postname%/’); } add_action(‘init’, ‘flush_permalinks’); // This does not solve
   it
 * We have also tried:
 * function flush_permalinks() {
    global $wp_rewrite; $wp_rewrite->flush_rules();}
   add_action(‘init’, ‘flush_permalinks’); // This does not solve it
 * And we have tried:
 * add_action( ‘init’, ‘create_initial_taxonomies’, 0 );
 * //This does not solve it.
 * Thanks in advance for any help or pointing us in the right direction for a solution!

The topic ‘wp_insert_term issue’ is closed to new replies.

## Tags

 * [permalinks](https://wordpress.org/support/topic-tag/permalinks/)
 * [wp_insert_term](https://wordpress.org/support/topic-tag/wp_insert_term/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [ErikStromme](https://wordpress.org/support/users/erikstromme/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/wp_insert_term-issue/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
