WordPress.org

Forums

How to correctly call flush_rewrite_rules() ? (5 posts)

  1. k12onos
    Member
    Posted 3 years ago #

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

  2. Pioneer Web Design
    Member
    Posted 3 years ago #

    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.

  3. k12onos
    Member
    Posted 3 years ago #

    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.

  4. k12onos
    Member
    Posted 3 years ago #

    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?

  5. Coldfight
    Member
    Posted 3 years ago #

    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(...);
    }

Topic Closed

This topic has been closed to new replies.

About this Topic