Executing my function once on a specific time

So the gist is that you have your function, you hook it into an action and then you tell WordPress to fire that action at some time on its schedule. The built in schedules that are available to you are:

  • hourly
  • twicedaily
  • daily

If you wanted to fire your event every hour, you would do something like this:

<?php

wp_schedule_event(time(), 'hourly', 'em_bookings_added');

If you want to get a task to run at a specific time, you can simply pass a unix timestamp as the first argument:

<?php

$future_time = mktime(10,0,0,30,9,2016); // 2016-09-30 10:00:00 UTC
wp_schedule_event($future_time, 'hourly', 'em_bookings_added');

If you have any arguments that you want to pass to your action, you can pass them as a fourth argument.

You can also specify a time that you would like your action to run — that’s the first argument. However please be aware that WordPress cron relies on people visiting the site to run and isn’t as accurate as a real cron job; no visitors == no cron running.

One way around this, however, is to set a cron job on your own server to trigger wp-cron.php manually:

Taken from Tom McFarlin’s awesome article on WordPress cron

// wp-config.php
define('DISABLE_WP_CRON', true);  

// in your crontab
/15 * * * wget -q -O - http://example.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

See more at https://codex.wordpress.org/Function_Reference/wp_schedule_event