wp_clear_scheduled_hook not working? (2 posts)

  1. WWDay3
    Posted 6 years ago #

    Not sure if this is the right forum to ask this, but here goes.

    I am working on a plugin that makes use of wp-cron. I have scheduled events using

    wp_schedule_event( time(), $postspan, "myhook1" , $num );

    which adds the hook just fine. But, when I try to remove the hook using


    it appears the hook is still there, and it has a next time to execute.

    I checked this out by adding the plugin "What's in Cron?", and then checked it by querying the cron entry in the options file. Shouldn't wp_clear_scheduled_hook just remove the hook from the cron array? I now have a bunch of hooks in there with the same name because the remove function is not removing them.

  2. Brandon Allen
    Posted 6 years ago #

    You have to call wp_clear_scheduled_hook() exactly the way you called wp_schedule_event(). In your case it would look like this:

    wp_schedule_event( time(), $postspan, "myhook1" , $num );
    $timestamp = wp_next_scheduled( 'myhook1');
    wp_clear_scheduled_hook( $timestamp, $postspan, "myhook1" , $num );

Topic Closed

This topic has been closed to new replies.

About this Topic