Title: the_permalink Function Incorrect After Custom Post Type Rewrite
Last modified: August 21, 2016

---

# the_permalink Function Incorrect After Custom Post Type Rewrite

 *  Resolved [seansean11](https://wordpress.org/support/users/seansean11/)
 * (@seansean11)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/the_permalink-function-incorrect-on-custom-post-rewrite/)
 * Hi,
 * I feel like I am probably making a stupid mistake, but can’t seem to figure out
   this issue. My permalink settings in the wp admin are set to post name ([http://example.com/%postname%/](http://example.com/%postname%/)).
   I have just modified my custom post type and its custom taxonomy slugs via the“
   rewrite” argument as follows:
 * custom post type:
    `'rewrite' => array( 'slug' => 'projects')`
 * custom taxonomy:
    `'rewrite' => array( 'slug' => 'projects/category' )`
 * The idea is that my custom posts will be located at [http://example.com/projects/post-title](http://example.com/projects/post-title)
   and my CPT category archives at [http://example.com/projects/category/category-name](http://example.com/projects/category/category-name).
   The rewrites seemed to work as expected because my custom posts and archives 
   are showing at those URL’s. The problem that I’m finding is that the function`
   the_permalink()` for these cpt posts is echoing out a URL of [http://example.com/post-title](http://example.com/post-title),
   which is not actually where the post exists. To give a little more information,
   I am setting up the post data via the setup_postdata() before the_permalink()
   is called.
 * I’ve tried refreshing permalinks, recreating my .htaccess files, using get_permalink(),
   changing around the rewrite slugs, changing themes, deactivating plugins, etc…
   I have a feeling that it may be something simple with the way my permalink settings
   and custom post type rewrite are interacting. Please let me know if you can fill
   me in with any valuable info.

Viewing 1 replies (of 1 total)

 *  Thread Starter [seansean11](https://wordpress.org/support/users/seansean11/)
 * (@seansean11)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/the_permalink-function-incorrect-on-custom-post-rewrite/#post-4863064)
 * So, after all of that testing and wasted time, this turned out to be something
   incredibly stupid.
 * When I had made the slug rewrites, I had also changed my custom post type name
   from ”casestudy” to “case_study.” I was setting up post data based on an Advanced
   Custom Field’s relationship field that I had set to restrict to the “casestudy”
   custom post type. When I made the name change, the relationship field kept the
   slug data of the “casestudy” post that I chose but defaulted back to restrict
   the fields as “posts” because “casestudy” no longer existed. So the URL’s went
   from `http://example.com/projects/case-study-title` to `http://example.com/case-
   study-title`.
 * Once I went back into the Advanced Custom Fields plugin and hooked the relationship
   field back up to the “case_study” custom post type, the_permalink started working
   correctly again.

Viewing 1 replies (of 1 total)

The topic ‘the_permalink Function Incorrect After Custom Post Type Rewrite’ is closed
to new replies.

## Tags

 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [permalinks](https://wordpress.org/support/topic-tag/permalinks/)
 * [slug](https://wordpress.org/support/topic-tag/slug/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [seansean11](https://wordpress.org/support/users/seansean11/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/the_permalink-function-incorrect-on-custom-post-rewrite/#post-4863064)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
