WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I changed permalinks in wp_options table in database and I'm getting 404 on every post. Everything works fine after I log in into the panel and click "save settings" on permalinks options page.

How to do this automatically (ie. "refresh" those settings)?

share|improve this question

migrated from serverfault.com Jul 31 '13 at 16:00

This question came from our site for system and network administrators.

Add flush_rewrite_rules(); to your theme's functions.php, load the page, and them remove it. It is very inefficient to have that run on every page load.

Hopefully your edits to the options table are sane. If not, that will not work.

Caveat: I think that functions.php is adequate. You may need to add it to a plugin or a mu-plugin file if that does not work correctly.

share|improve this answer

If you're writing a plugin, you should use this during activation, deactivation and uninstall. More info in that answer, but a quick example here.

function WCM_Setup_Demo_on_activation()
    if ( ! current_user_can( 'activate_plugins' ) )
    $plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
    check_admin_referer( "activate-plugin_{$plugin}" );

register_activation_hook(   __FILE__, 'WCM_Setup_Demo_on_activation' );

Just keep in mind that you should NOT do it on every page load/request!.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.