How to make wp cron job not fire immediately?

As described in wp_schedule_event first parameter is $timestamp – the first time that you want the event to occur. So just add interval to $timestamp. I think it should be like wp_schedule_event( time() + $delay, ‘interval1’, ‘my_cron_hook’ ); And set $delay as miliseconds before hook starts.

Running wp-cron from CLI

Or, you could use WP-CLI which was developed for scenarios like these. After a short installation like this $ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar $ chmod +x wp-cli.phar $ sudo mv wp-cli.phar /usr/local/bin/wp You can run your scheduled tasks like so $ wp cron event run –due-now –path=/var/www/mywebsite.com/ or via crontab (every 5mins) */5 * * * … Read more

What would be a PHP command to erase all posts from category X from the last month?

The first step is setting up the cron job. The second part requires querying the database for a specific post type where the entry is older than 1 week. We can do this with get_posts() and specifying the category argument and the date_query argument. //* If the scheduled event got removed from the cron schedule, … Read more

Recurring scheduled task help

You have to schedule your event in a hook, for example in after_setup_theme or wp actions: add_filter(‘cron_schedules’,’my_cron_definer’); function my_cron_definer($schedules){ $schedules[‘twomin’] = array( ‘interval’=> 120, ‘display’=> __(‘Once Every 2 Minutes’) ); return $schedules; } add_action(‘my_periodic_action’,’my_periodic_function’); function my_periodic_function(){ mail(’[email protected]’,’Test!’, ‘Test Message’); } add_action( ‘wp’, ‘wpse8170_setup_events’ ); // or add_action( ‘after_setup_theme’, ‘wpse8170_setup_events’ ); function wpse8170_setup_events() { if ( … Read more