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

Delete posts from a post type automatically via Cron

Although I do not understand the motivation for truncating posts, I think this exercise is valuable for you to understand how to use cron + WordPress. Create a function to truncate posts This can be used for both methods below WP-cron or UNIX cron. function foobar_truncate_posts(){ global $wpdb; # Set your threshold of max posts … Read more

Calling static method in the Widget Class

Try this instead: $gloabl $myxclass; $myxclass = new Xwidget(); add_action( ‘xxx_followers’, array(&$myxclass, “cron_addB” ) ); or add_action(‘xxx_followers’, “init_xclass_and_cron”); function init_xclass_and_cron() { $myxclass = new Xwidget(); $myxclass->cron_addB(); }

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

run a cron task without obstructing page load?

Cron tasks don’t directly affect page load besides the 0.01s timeout (of course, they do affect server load, so they can impact page load indirectly). My hunch is that your PHP config is the issue. The cron tasks run like any other web request, and they’re subject to PHP’s max_execution_time INI setting. If this is … Read more

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