• I am developing a plug-in but I can’t get the wp_schedule_event() function to work. Please see code below.

    function more_reccurences() {
    return array(
    'minutely' => array('interval' => 60, 'display' => 'Every Minute'),
    );
    }
    add_filter('cron_schedules', 'more_reccurences');
    
    add_action('wp_es_expire_posts','electric_studio_auto_post_expire');
    
    function my_activation() {
    	if ( !wp_next_scheduled( 'wp_es_expire_posts' ) ) {
        wp_schedule_event(time()+60, 'minutely', 'wp_es_expire_posts');
      }
    }
    
    //do_action('es_expire_posts');
    
    add_action('wp', 'my_activation');
    
    function electric_studio_auto_post_expire(){
      $expiredPosts = get_expiring_posts();
      foreach($expiredPosts as $thisPostID){
        expire_post($thisPostID);
      }
    
    }

    If I uncomment the line that starts ‘do_action’ the plug-in runs, but that is not ideal.

    The task is definitely scheduled as I installed the WP-CRON plugin and could see it there.

    Has anyone else had this problem or knows what I have done wrong??

  • The topic ‘Scheduling in my plugin’ is closed to new replies.