WordPress.org

Support

Support » How-To and Troubleshooting » How to correctly call flush_rewrite_rules() ?

How to correctly call flush_rewrite_rules() ?

  • Hi,

    I have several custom post types in my site and I added the flush_rewrite_rules() inside the last register post type function in my function.php theme file.

    This works and stops 404 pages, but after a while the rewrite_rules in wp_options started to act up and it periodically appear in my mysql_slow_queries log file.

    I’ve tried to search about this but find varying answers, lots of which I don’t know how to apply. I haven’t been able to understand the explanation in register post type codex on how to use it on register_activation_hook too.

    Can anyone please give me some help on how to correctly call flush_rewrite_rules()?

Viewing 4 replies - 1 through 4 (of 4 total)
  • This is quite dependent on how your site is designed and why you need to flush php (and what version of all is in use).

    immediately after the </head> try:
    <?php flush(); ?>

    works for most sites. If not visit php.net.

    isn’t that to speed up page loadings?

    What i’m referring to is flush_rewrite_rules() which is, according to various sources, should be added if you experience 404 pages with custom post types.

    Anyone got any idea on this?

    And I have another question,

    $wp_rewrite->flush_rules();

    and

    flush_rewrite_rules()

    are they basically the same thing?

    Anybody with an answer?

    I have that exact same question. The way I’m doing it right now, though (not sure if it’s correct), is:

    function foo() {
        bar();
        flush_rewrite_rules();
    }
    register_activation_hook( __FILE__, 'foo' );
    
    add_action('init', 'bar');
    function bar() {
        //...
        register_post_type( 'other' , $args );
        //register_taxonomy(...);
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to correctly call flush_rewrite_rules() ?’ is closed to new replies.
Skip to toolbar