• Resolved Klarom

    (@vargau)


    Hello

    I was testing to see if it’s possible to have a post under a CPT acting as an archive for another CPT, a would be nested CPT.

    I have a main page called Movies – /movies/

    I have also a CPT called Movies, the post type slug set to “mvs”, has archive, the archive set to /movies/ and it’s post url changed to /movies/. So all posts under Movies CPT will be like /movies/something-post.

    In the Movies CPT I have a post called “Harry Potter” and it’s url is /movies/harry-potter/

    Now I’ve created a new CPT called “Harry Potter”, the post tyle slug set to “hrpt”, has archive set to /movies/harry-potter and it’s post url changed to /movies/harry-potter, so all posts under Harry Potter CPT will be like /movies/harry-potter/something-post.

    Under this Harry Potter CPT I have created a post called “Summary” that would have the url /movies/harry-potter/summary.

    This post returns a 404.

    I can see the /movies/ acting properly as an archive.
    I can also see the /movies/harry-potter acting properly as an archive.
    But the posts under Harry Potter CPT return as 404.

    Is this not possible, or I am doing something wrong ?

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’m not going to say it’s not possible, because you got what feels like 50%-66% of the way there, but it’s definitely a complex thing going on when it comes to permalinks.

    Forgive if you understand this part in general. The /’s are meant to separate out the parts of the URL into the parts to query for. The permalink of /movies/harry-potter/summary would NORMALLY tell WordPress “we’re looking for a post type of movies, with a post named ‘harry-potter’ and it has a child post of ‘summary'”.

    In your case, if I’ve followed correctly, /movies/harry-potter/ is the entirety of the post type portion, with the rewrite field. Then the post name is “summary”. I could easily see WordPress possibly not interpreting that way, and perhaps thinking it’s meant to be a grandchild page from the “movies” main page you mention above, with “harry-potter” being the child page.

    Really depends on how WordPress is interpreting each, for which I can’t say for certain without being able to dig into its diagnostics with a rewrite analyzer plugin or probably Query Monitor.

    That said, my next question is what are you trying to achieve here? Why not 1 post type of “movies” and then posts for the movie titles, and then child posts of those for summary/cast/etc, whatever details you’re planning for?

    I think you could even potentially have a standard “page” at .com/movies and still have the post type of movies if you set archive to false. At least in case you were wanting a post editor screen for the .com/movies content.

    Thread Starter Klarom

    (@vargau)

    So kinda ended up using one of my past solutions, based on your recommendations.

    For Harry Potter CPT I’ve left the archive set to true with the custom archive slug set to to /movies/harry-potter/, but changed it’s custom url to “harry-potter”, even if this page doesn’t exist and won’t exist in this form.

    Now the /movies/harry-potter/ still works as an archive for CPT Harry Potter and returns all the posts under it. The posts under returns properly the posts and the 404 are gone.

    I’ve installed Permalink Manager (works also with the Lite version too) and changed the permastructure section, for Harry Pooter CPT from “harry-potter” change it to “movies/harry-potter”.

    Now I have a working archive for /movies/, working archive for /harry-potter/ and the posts under Harry Potter CPT work, while the “old” archive “/harry-potter/” gets redirected by Permalink Manager to the new one, /movies/harry-potter/.

    Thank you.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Sounds like you got it the rest of the way through, then.

    ??

    Let us know if you need anything else.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom post type with a post from a different custom post type’ is closed to new replies.