add_rewrite_rule not working with custom variables

It looks like your add_rewrite_rule function is not quite correct. The first parameter should be the regular expression pattern that you want to match, and the second parameter should be the query string that you want to rewrite the URL to. Also, you don’t need to include the file extension in the URL.

Try updating your custom_rewrite_rule function to this:

function custom_rewrite_rule() {
add_action('init', 'custom_rewrite_rule');

Replace PAGE_ID with the ID of the page that displays the custom template for your /episode/ URL. You can find the page ID by editing the page in WordPress and looking at the URL in your browser’s address bar – it will be something like post.php?post=PAGE_ID&action=edit.

This rule will match a URL like http://ngofwp.local/episode/2011/silly_donkey/ and rewrite it to http://ngofwp.local/index.php?page_id=PAGE_ID&ep_year=2011&ep_name=silly_donkey.

After updating the functions.php file, you’ll need to go to the WordPress dashboard Settings > Permalinks and click the “Save Changes” button to flush the rewrite rules cache and make your new rule active.