Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

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

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

2 Answers

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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

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