Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress cronjob every 3 minutes

Tags:

there are many post on stackoverflow with this topic but (i dont know why) nothing will work for me.

What i have

function isa_add_every_three_minutes( $schedules ) {      $schedules['every_three_minutes'] = array(             'interval'  => 180,             'display'   => __( 'Every 3 Minutes', 'textdomain' )     );      return $schedules; } add_filter( 'cron_schedules', 'isa_add_every_three_minutes' );   function every_three_minutes_event_func()  {     // do something }  wp_schedule_event( time(), 'every_three_minutes', 'every_three_minutes_event_func' ); 

Any ideas what i'm doing wrong?

like image 509
Peter Avatar asked Sep 12 '16 03:09

Peter


People also ask

How often should I run WP cron?

Creating a single job that calls your site's wp-cron. php script every 15 minutes is all you should need. WP-Cron will take care of the rest. You will need to adjust your job if you create new schedules that need to run more frequently than every 15 minutes.

How do I schedule a Cron job every 10 minutes?

Run a Cron Job after every 10 minutes The slash operator helps in writing the easy syntax for running a Cron job after every 10 minutes. In this command, */10 will create a list of minutes after every 10 minutes.

Which is the correct Cron job that runs every 5 minutes?

“At every 5th minute.” Cron job every 5 minutes is a commonly used cron schedule. We created Cronitor because cron itself can't alert you if your jobs fail or never start.


1 Answers

You need to use add_action() to hook your function to the scheduled event.

add_action( 'isa_add_every_three_minutes', 'every_three_minutes_event_func' ); 

Here is the full code.

// Add a new interval of 180 seconds // See http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules add_filter( 'cron_schedules', 'isa_add_every_three_minutes' ); function isa_add_every_three_minutes( $schedules ) {     $schedules['every_three_minutes'] = array(             'interval'  => 180,             'display'   => __( 'Every 3 Minutes', 'textdomain' )     );     return $schedules; }  // Schedule an action if it's not already scheduled if ( ! wp_next_scheduled( 'isa_add_every_three_minutes' ) ) {     wp_schedule_event( time(), 'every_three_minutes', 'isa_add_every_three_minutes' ); }  // Hook into that action that'll fire every three minutes add_action( 'isa_add_every_three_minutes', 'every_three_minutes_event_func' ); function every_three_minutes_event_func() {     // do something } ?> 
like image 138
Shivam Mathur Avatar answered Sep 25 '22 02:09

Shivam Mathur