Support » Fixing WordPress » Custom post type permalink structure

  • Hello,

    I’m trying to get my head around using permalinks with custom post types (CPT).

    I have a CPT called ‘Projects’ that contains multiple posts. I have also created a page template called ‘Showreel’ that displays all the ‘Project’ posts. The same posts are also displayed on my homepage in short form with a link to the relevant point on the Showreel page using anchors. When the user clicks on the link from my index page, he is taken to the following link (for example): /showreel#234 where 234 is the relevant post’s ID. I have attached an anchor with name=”234″ to the relevant post.

    Now this works fine, but isn’t great – ideally I’d like /showreel/this-project-name and it would have the same effect as /showreel#234.

    Because my CPT is called projects, all my custom permalink structures look like %postname%” (I realise this isn’t best practice, but I only have one page apart from index so it should be fine) and come out as /projects/this-project-name” which re-directs back to the homepage with no effect. I know I can use ‘rewrite => slug => showreel’ (omitting proper php formatting) to fake this effect, but I think this will confuse things further as my permalink still has no relation to the page named Showreel.

    How can I get my permalinks to behave as I’d like?


Viewing 2 replies - 1 through 2 (of 2 total)
  • Now this works fine, but isn’t great – ideally I’d like /showreel/this-project-name and it would have the same effect as /showreel#234.

    Sorry, I’m not 100% sure what you mean. Same effect, as in, use /showreel#this-project-name as anchor instead of post id?

    I too use Custom Post Type + Page Template in a similar way. I have a CPT called “store” which results in permalinks like /store/first, /store/second, and so on. I’ve also made a new Page Template which shows all posts of this type, and assigned URL /store to it. It works just fine as a “fake homepage” for this type of posts. So if you want this, all you have to do is change the slug of your CPT from “projects” to “showreel”. I guess?

    Sorry, I should have clarified a bit – I’d like /showreel/this-project-name essentially to redirect to /showreel#234 so that entering the first address would have the same effect as the second, if you see what I mean?

    Not sure of the best way to achieve this. I just need a pretty way for a client to be able to skip down to an individual post rather than using a # in the url if possible.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom post type permalink structure’ is closed to new replies.