• Hi all,

    I have added this function to rewrite some rules in wordpress:

    add_action( 'init', 'my_add_rewrite_rules' );   
    
    function mydid_add_rewrite_rules() {
     global $wp_rewrite;    
    
     add_rewrite_rule(....);
     .... Added some rewrite rules here...
    
     $wp_rewrite->flush_rules();
    }

    So far, everything works perfect.

    After browsing the urls, I supposed that the database containing the rewrite rules was updated and I have commented the line:

    // commented the line because this is an "expensive" action and I suppose that the
    // database is already updated
    // $wp_rewrite->flush_rules();

    However, after commenting, the url rewrite does not work. Why? Wasn’t the database already updated?

    p.s. I can not flush from the wp admin panel because of some theme’s constrains…

    Thank

Viewing 2 replies - 1 through 2 (of 2 total)
  • There is a typo in your function name (mydid_add), so the re-write probably didn’t happen until the line you commented out.

    Thread Starter yurako

    (@yurako)

    Oh, this is a typo here…

    Its actually

    add_action( 'init', 'mydid_add_rewrite_rules' );   
    
    function mydid_add_rewrite_rules() {
     global $wp_rewrite;    
    
     add_rewrite_rule(....);
     .... Added some rewrite rules here...
    
     $wp_rewrite->flush_rules();
    }

    The problem is that after I run – everything IS FINE.
    but the I comment the $wp_rewrite->flush_rules(); and it stops working.

    Why?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can I comment "flush" after flushing urls?’ is closed to new replies.