I have a scheduled event that runs twice daily in my plugin, the action is registered with


function fhprw_check_fetch($args){

//do stuff according to $type

if I manually call a do_action('fhprw_action',array('type'=>'uk')); when a widget is updated then the function receives $args as an array and I can get $type from $args['type'] no problem

but when I schedule an event with

wp_schedule_event(time() , 'twicedaily', 'fhprw_action',array('type'=>$instance['type'])); // ($instance['type'] will be 'uk')

then the function receives $args as a string

$args = 'uk' instead of array('type'=>'uk');

why is the function not receiving an array for $args when it is called by the cron?


scheduled events call the callback function with a list of parameters, not an array of parameters so my callback function for the action would receive $arg1,$arg2 etc and wouldn't be able to accept an associative array

1 Answer 1


It could be the phrasing of the array so try setting the array outside the wp_schedule_event call:

$args = array('type'=>$instance['type']);
wp_schedule_event(time() , 'twicedaily', 'fhprw_action',$args);
  • 3
    turns out that a scheduled event will call the callback function with call_user_func_array which means the function is called with fhprw_check_fetch($arg1,$arg2,$arg3) and not fhprw_check_fetch($arrarg);
    – CommentLuv
    Mar 19, 2011 at 15:02
  • 2
    In which case, if you really wanted args passed back as an associative array, you could schedule with $args = array( array( 'type' => $instance['type'] ) ); Mar 19, 2011 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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