WordPress.org

Ready to get started?Download WordPress

Forums

Custom post type permalink structure (3 posts)

  1. lowe_22
    Member
    Posted 2 years ago #

    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?

    Thanks

  2. chadrew
    Member
    Posted 2 years ago #

    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?

  3. lowe_22
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic