Wordpress

WordPress Register Post Type Slugs

I just came across a rather large “gotcha” when dealing with custom post types in WordPress. If you make any changes to the slug of a custom post type after it has been created, you’ll need to flush your rewrite rules afterwards for the changes to take effect.

flush_rewrite_rules();

I had to change one of my custom post types from:

$jb['has_archive'] = true;

to

$jb['has_archive'] = false;

I couldn’t figure out for the life of me why this post type’s archive page wasn’t able to be viewed. My theme’s 404 page was being shown instead. Low and behold I happened to scroll to the bottom of the Register Post Type Function Reference and there was an explanation about flushing rewrite rules to activate the changes.

I know. I know. RTFM, right?

This little function saved me from certain brain aneurysm, self-induced baldness and prison time.

Be careful though, this function should not be run on every page load.

flush_rewrite_rules WordPress Function Reference
Flushing Rewrite Rules

WordPress Christmas photo by Aliso the Geek.

Leave a Reply

Get Adobe Flash playerPlugin by wpburn.com wordpress themes