Adding custom rewrite rules to WordPress

My WordPress site has a portfolio that is at The portfolio sections & items are administered through a custom plugin I created. I want to access the individual items like & have that put “my-cool-photo” into a query string like ?portfolio_item=my-cool-photo so I can read it from my code.

In the plugins activation PHP file I have this code:

This adds the rewrite rule to the array OK. The problem is it’s not doing anything. When I go to I obtain the “This is somewhat embarrassing, isn’t it?” WordPress 404 error page. Obviously the redirect isn’t working, so the query string won’t be filled, yet just to make sure I did this:

…and sure enough the query string isn’t getting passed.

Is there something I’m missing?

After you update the WordPress rewrite rules, you need to flush them:

You can select to flush with the $hard parameter true, & then you should be able to see your rewrite rules in the .htaccess file.