Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Using rules in Posts

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:

  1. How to update custom fields using the wp_insert_post() function?
  2. Get meta_id along with meta_key and meta_value
  3. How can merge two arrays values in one array and save in database
  4. Check if user already visited this post today
  5. Display all meta for a post?
  6. How to display multiple Post meta_key/meta_values by SQL query
  7. the_post_thumbnail() based on the Post ID
  8. How to use multiple query with same meta key
  9. How to update single value in multi dimensional Post Meta?
  10. Can I write ‘RewriteCond’ using ‘functions.php’?
  11. Why is my get_post_meta always empty
  12. add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
  13. Compare two meta key values against each other inside the get_posts array?
  14. How can update custom meta for all posts
  15. WordPress Rewrite API calls not creating new rules
  16. Use ajax to update_post_meta
  17. Newbie question: no index.php? in my plain wordpress permalink
  18. how to increase custom post value by one most efficiently?
  19. Batch update a post meta field value of each post in Post Type
  20. How to Display Image Meta underneath EVERY image in EVERY post
  21. Change description on specific WooCommerce product status change
  22. Use WP_Query in shortcode
  23. Get Current User Id Inside a Loop Returns 0 For a Shortcode
  24. Random order of WP_Query results with highest meta value
  25. Static variable and add_rewrite_rule?
  26. The text box have space character
  27. how to remove metadata from the posts of my blog?
  28. How can I create a list of page titles from custom meta values?
  29. Trying to remove post thumbnail with plugin
  30. Randomly Assign an Image’s Alt Text Based on Data From Post
  31. Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
  32. Apache Fallback instead of add_rewrite_rule
  33. Performance impact of rewriting WordPress URLs
  34. Sort custom meta column by other meta value
  35. Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
  36. How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
  37. Creating user status mode in WordPress
  38. Need help with Google drive API [closed]
  39. Changes in permalink structure in WordPress and how to apply to in-site links
  40. WordPress Persistent connection rule does not work for “posts”
  41. Append query string to all URL’s
  42. custom rewrite rule help! Custom rewrite rules not applying to custom post type
  43. custom url rewrite for wordpress
  44. Archive post by meta value + 24hours
  45. WordPress update_post_meta updating with empty meta_value field [closed]
  46. Create custom permalinks to show Custom Post Type’s relationship?
  47. Is it possible to retrieve all posts with a certain value for metadata?
  48. Get post id within comments loop
  49. Non-Closing PHP Query in WordPress Loop
  50. Querying Database with wpdb
  51. update_post_meta only updating on last loop of foreach
  52. how to get serialized post meta
  53. Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
  54. How to use two meta_compare in an array?
  55. How to override url params with rewrite rules vars?
  56. Remove empty terms from array, sort alphabetically, update back to repeating field
  57. WordPress loop by meta key that is an array? and how loop multiple arrays
  58. WordPress yoast seo plugin – parse snippet var in meta description
  59. How to store multiple custom meta box
  60. How to add post meta in while loop?
  61. Add category to post meta
  62. Update post meta – Custom field does not match meta-key
  63. Order a WP_Query by meta value where the value is an array
  64. Save the value of a wp_dropdown_pages
  65. Add a custom class to the body tag using custom fields
  66. Define category ID using get_post_meta
  67. Unable to Call More than One Meta Box Output
  68. Hide a div when a custom field is empty
  69. Update value of a associative array with update_post_meta
  70. Front end file upload returning wrong attachment url
  71. Post meta select input, if statement
  72. Reverse Cross-Sells (WooCommerce)
  73. Remove item from post_meta array via AJAX
  74. When working with a post, almost all wp_postmeta are deleted
  75. Post Meta statement?
  76. Updating Lat and Lng of posts automatically gives sporadic results
  77. Adding user meta to post meta wp_insert_post() not working
  78. Efficient way of querying for a “fallback” post?
  79. WordPress AJAX load post metadata in modal
  80. Rewrite /keyword1+keyword2.html to search page | .htaccess
  81. get_post_meta with variable
  82. add_rewrite_rule questions
  83. Post from front end form to post_meta
  84. rewrite_rule – working fine but broken for pagination
  85. Order by in foreach
  86. retrieve wordpress post-meta using php not wordpress functions
  87. Postmeta not saving
  88. If custom field doesn’t exist, or exists and it’s true show title?
  89. how to exclude admin page from add_rewrite_rule in wordpress
  90. get_post_meta is always empty when I use wp_mail
  91. get_post_meta no longer working
  92. How to add together (get the sum) a field from all author’s posts
  93. Metadata on the WP_Post object
  94. How to display the date under the post title?
  95. WordPress add parameters with friendly url structure
  96. How do I get a function to work in single.php
  97. add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico
  98. How to modify default tags in wp_head()
  99. Same Custom Post Type Slug and Custom Taxonomy Slug, with hierarchial unique permalink structure
  100. How to Dynamically Change the author_base URL Slug by Language in WordPress?
Categories PHP Tags php, post-meta, rewrite-rules
How to use printf to output two links?
allowing subscriber role to delete their own posts

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress