I have 2 custom post types movies
(non-hierarchical) and series
(hierarchical). Each post from series
type has a meta field _movie
which contains a movie ID.
I want to specify a custom permalink structure for series
. What I need to achieve is a link http://example.com/series/movie_slug/parrent_series_slug/series_slug
(parent_series_slug is the slug of the parent of the series, they are hierarchical, if there isn’t any parent, parrent_series_slug
is omitted).
What I have achieved at the moment is http://example.com/series/parrent_series_slug/series_slug
, which is handled by WordPress. The question is how to insert movie_slug
(slug of the post with the ID from meta _movie
) in the permalink before series slug?
In this case it seems like you’ll want to hook into the WordPress rewrite rules.
{$permastruct}_rewrite_rules doesn’t have a lot of information, but this filter would allow you modify the array of existing rewrite rules to add in your new rewrite rule for series.
For this to work:
You’ll need to add in movie_slug, parrent_series_slug, and series_slug as vars that WordPress will recognize with the query_vars filter.
More information on WP_Rewrite with some examples