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

Sending out scheduled emails

You cannot rely on wp-cron for consistent results so you have to look to the server level. Most enterprise-level WordPress installations need some sort of consistent automation. This is how I automate WordPress in this type of situation. You will need to add a crontab to the server itself. If you’re running Linux, you can … Read more

execute function in wordpress plugin using crontab

I found a great solution here: Trigger a custom wordpress plugin with a linux cron My path was /usr/bin/wp so check your server. You can just add your function to a file, and using the wp bin script you don’t need to add anything to your php file to use WordPress functions. I was able … Read more

Schedule event every second thursday of the month

WordPress lets you add custom cron schedules, which is normally what you’d want to do in this situation, in conjunction with wp_schedule_event(). But, they work based on intervals rather than specific dates/times. For instance, add_filter( ‘cron_schedules’, ‘addCustomCronIntervals’ ); function addCustomCronIntervals( $schedules ) { $schedules[ self::PREFIX . ‘debug’ ] = array( ‘interval’ => 60 * 2, … Read more

WordPress Cron Schedule the if and else statement

wp_cron is a PHP level system and so also only runs on page load. It does not run on clock time so you’d still need to reload the page to get the loop to run. Second, to get this working with wp_cron you’d need to pull all of your posts with _limited_dates_to set and loop … Read more

Run function at specific time

you can absolutely use wp_cron to specify a time: add_action( ‘my_scheduled_event’, ‘prefix_my_scheduled_event’ ); /** * On the scheduled action hook, run a function. */ function prefix_my_scheduled_event() { // do something } //going to use the strtotime function, so a good habit to get into is to set the PHP timezone to UTC default_timezone_set( ‘UTC’ ); … Read more

Trigger a cron every 24h GMT -8

Almost, WP Cron jobs do not run at specific times, they are approximate, and all timestamps should be UTC, as WordPress always deals in UTC timestamps. If you want midnight PST, you’ll want to specify 8PM UTC. Also for example, your above code suggests midnight PST, but it may not run at midnight PST. If … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)