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)?


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.


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!.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy