WordPress.org

Support

Support » How-To and Troubleshooting » wp_clear_scheduled_hook not working?

wp_clear_scheduled_hook not working?

  • WWDay3
    Participant

    @wwday3

    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

    wp_clear_scheduled_hook(“myhook1”);

    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.

Viewing 1 replies (of 1 total)
  • 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 );

Viewing 1 replies (of 1 total)
  • The topic ‘wp_clear_scheduled_hook not working?’ is closed to new replies.