• Resolved seansean11

    (@seansean11)


    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 (https://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 https://example.com/projects/post-title and my CPT category archives at https://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 https://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

    (@seansean11)

    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 https://example.com/projects/case-study-title to https://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.