How to: hierarchical url for custom post type

I'm migrating a site to Wordpress and would like to replicate the structure of my old urls as much as possible. Here's what I'm trying to do using CustomPress:

/videos/my-show/season-4/slug-name-here/

I have setup a post type called 'video' and also used the built-in Category option to create categories like Videos -> My Show -> Season 4.

The archive page works correctly at /videos/my-show/season-4/, but my post pages in that category still show up as /video/slug-name-here/.

Is it possible to do this? Can you provide a simple example?

Thanks for the help!

  • Arnold

    Problem is Wordpress is going to be able to address pages by several different URLs. You may be going direct as /video/slug/ You may be going through categories as /videos/slug/. You post may be in several different categories so /videos/slug1 or /videos/slug2/ and /videos/slug/slug3/ may point to the same page.

    Then in general the shortest URL pointing to the page will be the one used So you can probably get tehurl you want to work and deliver the right page but it won't persist and display the same way every time.

  • Todd

    Okay, I see what you mean. If I set the post type to be hierarchical, then I get the Parent dropdown in the admin page. If I create each of the category levels as parents and my video post as the last level, then I get the url hierarchy I was expecting. Only goofy part is that each category level also shows my video custom fields, which obviously wouldn't be used on a category.

    Any way to hide the post type base name at the front of the url? The post type setting for rewriting seems to have no effect.

    Also, since the categories are now posts, the Filed Under label always shows empty, so I'll have to hide that.

  • Arnold

    Rewrite should work but you have to have something for WP to parse

    for example if your post type name was "my_video" you could in the Rewrite area put in just "video". Not that if you want a different name for the Archive view you should also change the Has Archive to a rewrite string. I usually make rewrite the singular "video" and the Archive the plural "videos".

    You may be confusing things. The Post type being hierarchical is primarily used for things like attachment so you can associate other post_types with a parent post type. There is a built in "attachments" post type that handles images and files. Setting the attachments parent to a given post associates it with that post.

    I was thinking more in terms of hierarchical taxonomies.

    With a taxonomy the url starts with the taxonomies name or it' rewrite. So if you had a taxonomy called "genre" your urls would look like /genre/sci-fi. If you wanted to break down genre you could do /genre/mystery/sci-fi/ and /genre/horror/sci-fi/ No post type in the url because the taxonomy defines it.

  • Arnold

    No with taxonomy genre and post type video what you would get is

    /video/little-shop-of-horrors/ - single listing
    /genre/sci-fi/ - list of all genre sci-fi listings which would include lsoh
    /genre/horror/ - list of all genre horror listings which would include lsoh
    /genre/horror/sci-fi - list of all genre horror/sci-fi listings which would include lsoh

    If you used hierarchical post type you would get

    /video/genre/horror/sci-fi/little-shop-of-horrors/

    But that's it

    You'd have three separate pages. /video/genre/, /video/genre/horror/, and /video/genre/horror/sci-fi/

    Taxonomies are lists of related items. Hierarchical page are just one page that is related to other pages.

    Now you could use both. Then you'd get

    /video/genre/horror/sci-fi/little-shop-of-horrors/ - single
    /genre/sci-fi/ - list of all genre sci-fi listings which would include lsoh
    /genre/horror/ - list of all genre horror listings which would include lsoh
    /genre/horror/sci-fi - list of all genre horror/sci-fi listings which would include lsoh

  • Todd

    So here's my concern and why I'm looking to do hierarchical urls for our video pages. Since we do a new show season each year, it's possible a show could be named the same thing, despite being in different show years, such as:

    Season 1:
    /video/episode-2-my-favorite-video-title/
    Season 3:
    /video/episode-2-my-favorite-video-title/

    Obviously that doesn't work, so it needs to be:

    /video/season-3/episode-2-my-favorite-video-title/

    Just trying to come up with the best way to handle this.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.