Template Tag not available in real Cron Jobs

When you run things on the CLI (which is pretty much where Cronjob and runwhen jobs are running), then you don’t have access to some things like some server or request variable contents, etc. What you need to do is fire up WP Core. Else you won’t have access to the full WP API. One … Read more

Web Scraping with Cron

You don’t necessarily need to use the WP Cron API for this. Instead you could modify your existing code to make use of WP Transients. Transients are basically Options that expire after a set time. You can wrap your current scrape process in an if statement that checks for the existence of the stored transient. … Read more

WP Cron job every 1st and 15th of the month

wp_cron operates on intervals and there is no interval that will hit exactly the first day and the 15th of every month. You could run your wp-cron job every day and check the date, similar to this but with a simple callback like: cron_callback_wpse_113675() { $date = date(‘d’); if (’01’ == $date || ’15’ == … Read more

Cronjob returns a lot of REMOTE_ADDR, SERVER_PORT, SERVER_NAME, etc errors

You’re getting Undefined index errors because you’re loading the files directly and not rendered through the server. The server typically populates those values and it’s actually more secure to run with less elevated privileges (through an HTTP request). Throw your manual cron to a curl or wget — whichever you have installed on your server. … Read more

How do I get a Function in my functions.php to execute with a cron job?

When you use *nix cron to run a PHP file like that it won’t have WordPress loaded. You can load it manually, but a better method is to use WordPress’ own cron API. Schedule the event in your functions.php: if ( ! wp_next_scheduled( ‘expire_posts’ ) ) { wp_schedule_event( time(), ‘hourly’, ‘expire_posts’ ); } I’ve used … Read more

How do i schedule cron in wordpress for each second?

I do not think it is useful to have a cron running every second, but the function itself is quite simple. You add a filter to the cron_schedules: function f711_add_seconds( $schedules ) { $schedules[‘everysecond’] = array( ‘interval’ => 1, ‘display’ => __(‘Every Second’) ); return $schedules; } add_filter( ‘cron_schedules’, ‘f711_add_seconds’ ); You can now use … Read more