Title: Changing Custom Post Permalink Structure
Last modified: August 20, 2016

---

# Changing Custom Post Permalink Structure

 *  [magicwings](https://wordpress.org/support/users/magicwings/)
 * (@magicwings)
 * [14 years ago](https://wordpress.org/support/topic/changing-custom-post-permalink-structure/)
 * Hi all,
 * I’m running a theme which uses custom post types. However, I wish to change the
   permalinks to my posts to include the PostID.
 * I have added this code:
 *     ```
       add_action('init', 'movies_rewrite');
       function movies_rewrite() {
           global $wp_rewrite;
           $wp_rewrite->add_permastruct('movies', 'Movies-detail/%postname%-%post_id%', true, 1);
           add_rewrite_rule('movies/([0-9]{4})/(.+)/?$', 'index.php?movies=$matches[2]', 'top');
           $wp_rewrite->flush_rules(); // !!!
   
       }
       ```
   
 * …and it works!
 * If I go to [http://www.example.com/Movies-detail/examplepost-1234/](http://www.example.com/Movies-detail/examplepost-1234/),
   it comes up with the correct post, and everything’s updated.
 * Well… not quite.
 * All of the links on every page still point to the old permalinks, resulting in
   a 404 error: they’re not updated.
 * I’ve gone to the Settings>>Permalinks page and saved the settings, changed them
   and re-saved, cleared my server cache, my local cache, everything, and I’m finally
   led to assume it’s a problem in the code – or a line or two I’ve missed.
 * How can I update all the permalinks on my site to direct to the new structure?
 * Thanks in advance

The topic ‘Changing Custom Post Permalink Structure’ is closed to new replies.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [permalink](https://wordpress.org/support/topic-tag/permalink/)
 * [post](https://wordpress.org/support/topic-tag/post/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [magicwings](https://wordpress.org/support/users/magicwings/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/changing-custom-post-permalink-structure/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
