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.
Related Posts:
- Get meta_id along with meta_key and meta_value
- How can merge two arrays values in one array and save in database
- Check if user already visited this post today
- Display all meta for a post?
- How to display multiple Post meta_key/meta_values by SQL query
- the_post_thumbnail() based on the Post ID
- How to use multiple query with same meta key
- How to update single value in multi dimensional Post Meta?
- Can I write ‘RewriteCond’ using ‘functions.php’?
- Why is my get_post_meta always empty
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- Compare two meta key values against each other inside the get_posts array?
- How can update custom meta for all posts
- WordPress Rewrite API calls not creating new rules
- Use ajax to update_post_meta
- Newbie question: no index.php? in my plain wordpress permalink
- Batch update a post meta field value of each post in Post Type
- Change description on specific WooCommerce product status change
- Use WP_Query in shortcode
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Random order of WP_Query results with highest meta value
- Static variable and add_rewrite_rule?
- The text box have space character
- how to remove metadata from the posts of my blog?
- How can I create a list of page titles from custom meta values?
- Trying to remove post thumbnail with plugin
- Apache Fallback instead of add_rewrite_rule
- Performance impact of rewriting WordPress URLs
- Sort custom meta column by other meta value
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- Creating user status mode in WordPress
- Need help with Google drive API [closed]
- Append query string to all URL’s
- custom rewrite rule help! Custom rewrite rules not applying to custom post type
- custom url rewrite for wordpress
- Archive post by meta value + 24hours
- WordPress update_post_meta updating with empty meta_value field [closed]
- Create custom permalinks to show Custom Post Type’s relationship?
- Get post id within comments loop
- Non-Closing PHP Query in WordPress Loop
- Querying Database with wpdb
- update_post_meta only updating on last loop of foreach
- how to get serialized post meta
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- How to use two meta_compare in an array?
- How to override url params with rewrite rules vars?
- Remove empty terms from array, sort alphabetically, update back to repeating field
- WordPress loop by meta key that is an array? and how loop multiple arrays
- WordPress yoast seo plugin – parse snippet var in meta description
- How to add post meta in while loop?
- Add category to post meta
- Update post meta – Custom field does not match meta-key
- Order a WP_Query by meta value where the value is an array
- Add a custom class to the body tag using custom fields
- Define category ID using get_post_meta
- Unable to Call More than One Meta Box Output
- Hide a div when a custom field is empty
- Post meta select input, if statement
- WordPress Rewrite Rule
- WordPress stripping out custom field tags
- Prevent Buddypress Rewrite Rules on Non-Buddypress pages/posts
- How to check post meta isset or not empty during publish/save post?
- get value from get_post_meta then reuse it in another get_post_meta
- Order category posts by last word of custom field
- Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
- Loop for recently (updated_post_meta) posts?
- How to add and subtract user meta values after post meta update
- How to update custom fields when post is published?
- Update Images after edit via php
- No more get_option(‘date_time’) in WordPress 5.5?
- Delete post meta by serialized meta value
- Using zip code to display custom data in Admin Order Details
- Show a text if the post has written by author user role in WordPress
- Fix common misspellings/errors based on array of replacements
- update_post_meta Not Processing Array Data (Not Sure What I Am Missing)
- Unable to update the meta boxes with multiple fields
- WP post meta – for loop inside for loop
- Reverse Cross-Sells (WooCommerce)
- Remove item from post_meta array via AJAX
- When working with a post, almost all wp_postmeta are deleted
- Post Meta statement?
- Updating Lat and Lng of posts automatically gives sporadic results
- WordPress AJAX load post metadata in modal
- Rewrite /keyword1+keyword2.html to search page | .htaccess
- get_post_meta with variable
- Post from front end form to post_meta
- rewrite_rule – working fine but broken for pagination
- Postmeta not saving
- If custom field doesn’t exist, or exists and it’s true show title?
- how to exclude admin page from add_rewrite_rule in wordpress
- get_post_meta is always empty when I use wp_mail
- How to add together (get the sum) a field from all author’s posts
- Metadata on the WP_Post object
- How to display the date under the post title?
- WordPress add parameters with friendly url structure
- How do I get a function to work in single.php
- add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico
- How to modify default tags in wp_head()
- Same Custom Post Type Slug and Custom Taxonomy Slug, with hierarchial unique permalink structure