how to refresh wordpress permalink settings? (without admin panel)

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

Related posts

2 comments

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

  2. 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' ) )
            return;
        $plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
        check_admin_referer( "activate-plugin_{$plugin}" );
    
        flush_rewrite_rules();
    }
    register_activation_hook(   __FILE__, 'WCM_Setup_Demo_on_activation' );
    

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

Comments are closed.