0

I use wp_schedule_event to have the function updatePostCounts() executed every hour. I also use the plugin "WP Crontrol" which shows me that the hook (opbs_update_counts) is there and is run every hour. But when the time is due nothing happens - updatePostCounts() isn't executed. Here's the code.

public function __construct()
{
    $this->addActions();
    register_deactivation_hook(__FILE__, array($this, 'deactivation'));
}
public function deactivation()
{
    wp_clear_scheduled_hook('opbs_update_counts');
}


public function addActions()
{

      if( !wp_next_scheduled('opbs_update_counts') )
    {
        wp_schedule_event(time(), 'hourly', 'opbs_update_counts');
    }
    add_action('opbs_update_counts', array('cronTaskUpdateCounts'));

    add_action('init', array($this, 'action_init'));

        add_action('template_redirect', array($this, 'action_template_redirect'));

}

    public function cronTaskUpdateCounts()
{
     $this->updatePostsCounts();
}

what could be the problem?

2
add_action('opbs_update_counts', array('cronTaskUpdateCounts'));

should be

add_action( 'opbs_update_counts', array( $this, 'cronTaskUpdateCounts' ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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