You’re almost there. You need to add the season
and episode
query vars to the array of recognized vars. Note the small change to your regex as well-
function wpd_add_my_rule(){
add_rewrite_rule(
'^([^/]+)/season-([0-9]+)/episode-([0-9]+)/?$',
'index.php?name=$matches[1]&season=$matches[2]&episode=$matches[3]',
'top'
);
}
add_action( 'init', 'wpd_add_my_rule' );
function wpd_add_query_vars( $query_vars ) {
$query_vars[] = 'season';
$query_vars[] = 'episode';
return $query_vars;
}
add_filter( 'query_vars', 'wpd_add_query_vars' );
You can use get_query_var()
in the template to fetch the values.