how to set array of args for scheduled event?

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

add_action('fhprw_action','fhprw_check_fetch'); 

function fhprw_check_fetch($args){
  $type=$args['type'];

//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

Read More

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?

[edit]

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

Related posts

Leave a Reply

1 comment

  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);