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. Get meta_id along with meta_key and meta_value
  2. How can merge two arrays values in one array and save in database
  3. Check if user already visited this post today
  4. Display all meta for a post?
  5. How to display multiple Post meta_key/meta_values by SQL query
  6. the_post_thumbnail() based on the Post ID
  7. How to use multiple query with same meta key
  8. How to update single value in multi dimensional Post Meta?
  9. Can I write ‘RewriteCond’ using ‘functions.php’?
  10. Why is my get_post_meta always empty
  11. add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
  12. Compare two meta key values against each other inside the get_posts array?
  13. How can update custom meta for all posts
  14. WordPress Rewrite API calls not creating new rules
  15. Use ajax to update_post_meta
  16. Newbie question: no index.php? in my plain wordpress permalink
  17. Batch update a post meta field value of each post in Post Type
  18. Change description on specific WooCommerce product status change
  19. Use WP_Query in shortcode
  20. Get Current User Id Inside a Loop Returns 0 For a Shortcode
  21. Random order of WP_Query results with highest meta value
  22. Static variable and add_rewrite_rule?
  23. The text box have space character
  24. how to remove metadata from the posts of my blog?
  25. How can I create a list of page titles from custom meta values?
  26. Trying to remove post thumbnail with plugin
  27. Apache Fallback instead of add_rewrite_rule
  28. Performance impact of rewriting WordPress URLs
  29. Sort custom meta column by other meta value
  30. Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
  31. How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
  32. Creating user status mode in WordPress
  33. Need help with Google drive API [closed]
  34. Append query string to all URL’s
  35. custom rewrite rule help! Custom rewrite rules not applying to custom post type
  36. custom url rewrite for wordpress
  37. Archive post by meta value + 24hours
  38. WordPress update_post_meta updating with empty meta_value field [closed]
  39. Create custom permalinks to show Custom Post Type’s relationship?
  40. Get post id within comments loop
  41. Non-Closing PHP Query in WordPress Loop
  42. Querying Database with wpdb
  43. update_post_meta only updating on last loop of foreach
  44. how to get serialized post meta
  45. Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
  46. How to use two meta_compare in an array?
  47. How to override url params with rewrite rules vars?
  48. Remove empty terms from array, sort alphabetically, update back to repeating field
  49. WordPress loop by meta key that is an array? and how loop multiple arrays
  50. WordPress yoast seo plugin – parse snippet var in meta description
  51. How to add post meta in while loop?
  52. Add category to post meta
  53. Update post meta – Custom field does not match meta-key
  54. Order a WP_Query by meta value where the value is an array
  55. Add a custom class to the body tag using custom fields
  56. Define category ID using get_post_meta
  57. Unable to Call More than One Meta Box Output
  58. Hide a div when a custom field is empty
  59. Post meta select input, if statement
  60. WordPress Rewrite Rule
  61. WordPress stripping out custom field tags
  62. Prevent Buddypress Rewrite Rules on Non-Buddypress pages/posts
  63. How to check post meta isset or not empty during publish/save post?
  64. get value from get_post_meta then reuse it in another get_post_meta
  65. Order category posts by last word of custom field
  66. Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
  67. Loop for recently (updated_post_meta) posts?
  68. How to add and subtract user meta values after post meta update
  69. How to update custom fields when post is published?
  70. Update Images after edit via php
  71. No more get_option(‘date_time’) in WordPress 5.5?
  72. Delete post meta by serialized meta value
  73. Using zip code to display custom data in Admin Order Details
  74. Show a text if the post has written by author user role in WordPress
  75. Fix common misspellings/errors based on array of replacements
  76. update_post_meta Not Processing Array Data (Not Sure What I Am Missing)
  77. Unable to update the meta boxes with multiple fields
  78. WP post meta – for loop inside for loop
  79. Reverse Cross-Sells (WooCommerce)
  80. Remove item from post_meta array via AJAX
  81. When working with a post, almost all wp_postmeta are deleted
  82. Post Meta statement?
  83. Updating Lat and Lng of posts automatically gives sporadic results
  84. WordPress AJAX load post metadata in modal
  85. Rewrite /keyword1+keyword2.html to search page | .htaccess
  86. get_post_meta with variable
  87. Post from front end form to post_meta
  88. rewrite_rule – working fine but broken for pagination
  89. Postmeta not saving
  90. If custom field doesn’t exist, or exists and it’s true show title?
  91. how to exclude admin page from add_rewrite_rule in wordpress
  92. get_post_meta is always empty when I use wp_mail
  93. How to add together (get the sum) a field from all author’s posts
  94. Metadata on the WP_Post object
  95. How to display the date under the post title?
  96. WordPress add parameters with friendly url structure
  97. How do I get a function to work in single.php
  98. add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico
  99. How to modify default tags in wp_head()
  100. Same Custom Post Type Slug and Custom Taxonomy Slug, with hierarchial unique permalink structure
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
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 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