Running Cron every 2 hours [duplicate]

An asterisk in the minute (first) field tells it to run every minute, regardless of the other fields. You need to specify an exact minute to run within the hour. Be that on the hour (0), half past (30), etc.. 0 */2 * * * /path-to-script

wp_schedule_event didn’t work

Cron fires outside of the standard WordPress loop, so $post will not be filled with any post-related data when the function is called. It should be obvious, then, that providing an ID directly isn’t referencing the non-existent $post variable which is why it works in that scenario. The best way to set post_statuses to expired … Read more

Dynamic name of cron event

So no, I can’t see a way to grab the name of your action. However, you can pass arguments to your callback: $blog_id = get_current_blog_id(); $cron_name=”import_blog_posts_in_network_daily_”.$blog_id; if ( !wp_next_scheduled( $cron_name) ) { wp_schedule_event( time(), ‘daily’, $cron_name, array($blog_id) ); } add_action( $cron_name, array($this, ‘import_blog_posts_in_network’) ); /* public function import_blog_posts_in_network($blog_id) { // do something for blog $blog_id … Read more

escaping double quotes and percent signs (%) in cron

You have to escape the % signs. They have a special meaning in crontabs: man (5) crontab: Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

WordPress cronjob get scheduled but function does not run

I believe you need to use wp_get_current_user() (see https://codex.wordpress.org/Function_Reference/wp_get_current_user ), which will return the current WP user information as an object. From there, you can get the user name (or other parameters). From that page, this example should get you started: $current_user = wp_get_current_user(); /** * @example Safe usage: $current_user = wp_get_current_user(); * if ( … Read more