• Resolved itism64

    (@itism64)


    Hi, I need to test something (website loose permalinks sometimes) when i resave permalinks all works again.

    Found this but that does not work as it own time interval

    // Flush permalinks every hour
    add_action(‘my_hourly_event’, ‘do_this_hourly’);

    function my_activation() {
    if ( !wp_next_scheduled( ‘my_hourly_event’ ) ) {
    wp_schedule_event(time(), ‘hourly’, ‘my_hourly_event’);
    }
    }

    add_action(‘wp’, ‘my_activation’);

    function do_this_hourly() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
    }

    How do i create or what code must i use with your plugin ?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    At a glance this looks correct to me but it’s well outside of the support I can provide. Running this code via WP Crontrol won’t result in different behaviour.

    Best of luck.

    Thread Starter itism64

    (@itism64)

    Thanks will check it

    @itism64 your code seems to have some syntax errors and incorrect function names. Try this corrected version:

    // Flush permalinks every hour
    add_action('my_hourly_event', 'do_this_hourly');
    
    function my_activation() {
        if (!wp_next_scheduled('my_hourly_event')) {
            wp_schedule_event(time(), 'hourly', 'my_hourly_event');
        }
    }
    
    add_action('wp', 'my_activation');
    
    function do_this_hourly() {
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
    }
    

    In the code snippet above, the main changes made were:

    • Replaced the single quotation marks around function and action names with normal single quotation marks (' instead of and ).
    • Adjusted the indentation for better code readability.

    Please note that this code should be placed in the appropriate location within your WordPress theme or in a custom plugin file.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Rewrite permalinks’ is closed to new replies.