WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have several cron jobs all hooked to the same hook, but each with a different argument (a post ID). It appears wp_clear_scheduled_hook only clears job which match the argument passed with it (or jobs without any arguments, if no argument is provided).

Is there a way to delete all the cron jobs associated with a hook, regardless of the argument that job has? (Without doing so 'manually' by looping through the IDs).

Seems an answer was deleted! To clarify what I would like to achieve: each post has an expiration date - and I would like to delete the post after this date.

(An alternative option is to have one cron job - repeating every 24 hours that deletes any expired posts).

However, I decided to create a one-off job for each post - but it seems you can't delete all the jobs at once without cycling through them.

share|improve this question
up vote 10 down vote accepted

I have just quickly wrote the below function, it will clear all crons for the specified hook, irrespective of the cron time and the hook argument.

NOTE: I have NOT TESTED the function, so please don't run it on your live site.

function wpse39681_clear_all_crons( $hook ) {
    $crons = _get_cron_array();
    if ( empty( $crons ) ) {
    foreach( $crons as $timestamp => $cron ) {
        if ( ! empty( $cron[$hook] ) )  {
            unset( $crons[$timestamp][$hook] );

        if ( empty( $crons[$timestamp] ) ) {
            unset( $crons[$timestamp] );
    _set_cron_array( $crons );

Related: http://core.trac.wordpress.org/ticket/18997

share|improve this answer
Thanks Hameedullah. I decided to go with the alternative option, since that is how WordPress deletes old trashed posts. I've not tested your function, but it looks right and would do the job. Thanks again. – Stephen Harris Jan 21 '12 at 21:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.