Custom interval is not working

Note on input arguments: You are using the filter callback function (FCB) with two input arguments, but the default is one. In general you should replace: add_filter( ‘some_filter’, ‘some_filter_callback’ ); function some_filter_callback( $arg1, $arg2 ) { with something like: add_filter( ‘some_filter’, ‘some_filter_callback’, 10, 2 ); function some_filter_callback( $arg1, $arg2 ) { if you want two … Read more

Managing scheduled tasks

It looks to me that this line add_action(‘obr_scheduled_task’, array(&$this, ‘obr_activate_scheduled_task’)); should be add_action(‘obr_scheduled_task’, array(&$this, ‘obr_scheduled_task’)); otherwise you are re-scheduling on every page visit. Edit: Here is a logger that can be useful when debugging wp-cron: function my_logger($var){ $logfile=”/tmp/logger.txt”; // EDIT this to your needs file_put_contents($logfile, date(“Y-m-d: H:i:s”,time()).” — “.print_r($var, true).”\n”, FILE_APPEND); } You can use … Read more

Posts wont expire

create for these posts a customfield with the name expires and the value is the date for disabling the post. Use the following code in the Loop of your theme. //Loop-Start if (have_posts()) : while (have_posts()) : the_post(); $exTime = get_post_custom_values(‘expires’); if (is_array($exTime)) { $exString= implode($exTime); $seconds = strtotime($exString) – time(); } else { $secondes … 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

How to make sure that only one wp_cron() runs at a time?

Yes, it is possible… And to be honest, it’s often very important to do this… WP Scheduler sometimes tends to cause problems, when cron tasks are long… So how I solve this problem? I use Transients API to implement semaphores… Here’s the code: if ( ! wp_next_scheduled( ‘my_task_hook’ ) ) { wp_schedule_event( time(), ‘hourly’, ‘my_task_hook’ … 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

what is firing cron

Well, it isn’t the best tutorial I’ve came across, so I get why you’re confused… Smashing Magazine has a little bit better tutorial on this subject. Some quotes from this article that should help you understand how does WP Cron work… WordPress Cron is what many people refer to as a “pseudo-cron system.” The difference … Read more

Run a cron job (or similar) in the background of WP after post update/create

Alright, here’s some code I just whipped up. Completely untested, just wrote it right off the cuff…so don’t expect it to work 100% when you drop it in, but the core concept is there, as is a decent amount of the legwork add_action( ‘my_filter_posts_content’, ‘my_filter_content’ ); add_action( ‘save_post’, ‘my_set_content_filter’ ); if( !wp_next_scheduled( ‘my_filter_posts_content’ ) ) … 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)