19 votes

Should I disable WP_CRON and trigger wp-cron.php from the server?

There is no downside for running WP CRON using the server's cron jobs. In fact this is the recommended practice. According to Official WordPress Plugin Development Document: WP-Cron does not run ...
Fayaz's user avatar
  • 8,909
18 votes

Running WP-Cron on Multisite networks the right way?

After you've added the constant in wp-config.php defined('DISABLE_WP_CRON') or define('DISABLE_WP_CRON', true); WP-CLI And assuming you have your config.yml setup correctly, you can ommit the --...
jgraup's user avatar
  • 9,744
15 votes
Accepted

Uncaught Error: Call to undefined function wp_generate_attachment_metadata() @ wp-cron

Some of what is usually admin side functionality is not included as part of the "main" wordpress bootstrap, files containing uploaded file manipulation functions are one of them and you need to ...
Mark Kaplun's user avatar
  • 23.4k
11 votes

Running WP-Cron on Multisite networks the right way?

Easier one-liner with less bash: wp site list --field=url | xargs -i -n1 wp cron event run --due-now --url="{}" You can either run it manually or put it in a script and call it from cron as in the ...
Anastis's user avatar
  • 576
11 votes

Delete thousands of cron jobs

Wordpress cron events can also be cleared from the command line, using WP-CLI: wp cron event list wp cron event delete your_example_event More details in the wp-cli docs.
Paul Wenzel's user avatar
11 votes

Do WordPress cron jobs slow down page loading?

The short answer is actually yes, in most cases. Firstly, on most set-ups, spawning a cron job incurs a 1 second delay on page load, because it is done via a loopback HTTP request with a 1 second ...
Jake's user avatar
  • 211
10 votes

How to debug WordPress "Cron" wp_schedule_event

You could debug manually, by creating an action and executing the Cron action inside. Like this: add_action( 'init', function() { if ( ! isset( $_GET['the_cron_test'] ) ) { return; } ...
WPMaster's user avatar
  • 101
6 votes
Accepted

What would be a PHP command to erase all posts from category X from the last month?

The first step is setting up the cron job. The second part requires querying the database for a specific post type where the entry is older than 1 week. We can do this with get_posts() and specifying ...
Nathan Johnson's user avatar
5 votes

"Could not open input file: wp-cron.php?import_key=" in shell?

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 ...
kero's user avatar
  • 6,200
5 votes

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 ...
TheDeadMedic's user avatar
  • 36.4k
5 votes

Check if event was scheduled - schedule event only once

Have you ever heard of Rubber Ducking? The official documentation has an answer: if ( ! wp_next_scheduled( 'woofio_hourly' ) ) { wp_schedule_event( time(), 'hourly', 'woofio_hourly' ); }
Pavel Janicek's user avatar
4 votes

WP Cron Doesn't Execute When Time Elapses

For anyone protecting their (development) site from public access, HTTP Authentication can be the cause of WP Cron not functioning. In case it can help anyone, here is my list of things I did before ...
sampi's user avatar
  • 159
4 votes
Accepted

Delete all scheduled events with a particular hook

4.9.0 introduced wp_unschedule_hook() https://developer.wordpress.org/reference/functions/wp_unschedule_hook/
Jason Rikard's user avatar
4 votes

Using WP_Query and WP_Meta_Query Outside of Wordpress

This is what worked for me: require_once 'wp-config.php'; global $wpdb; $args = array( 'post_type' => 'product', 'posts_per_page' => -1, ); $Query= new WP_Query($...
Aniruddha Gawade's user avatar
4 votes
Accepted

get_posts / WP_Query Memory size of 134217728 bytes exhausted

If all you want is printing ID in a file, then you may write custom query for it. That way you'll be able to avoid some internal processing WordPress does. Many posts may exhaust your RAM, although I ...
Fayaz's user avatar
  • 8,909
4 votes
Accepted

Will cron job run if page loaded is being served from cache?

It depends on the plugin and the cache method you are using. For example, as far as I remember, WP Super Cache offers two different cache methods: PHP Cache HTML Cache Using the first method creates ...
Johansson's user avatar
  • 15.3k
3 votes

cron job to auto delete posts of a specific post type older than x days

// add the schedule event if it has been removed if( ! wp_next_scheduled( 'mg_remove_old_entries' ) ) { wp_schedule_event( time(), 'daily', 'mg_remove_old_entries' ); //run the event daily } // ...
MagniGeeks Technologies's user avatar
3 votes

How to test wp_cron?

wp-cli is another way: Listing Events > wp cron event list +-------------------+---------------------+-----------------------+---------------+ | hook | next_run_gmt | ...
Ian Dunn's user avatar
  • 4,837
3 votes
Accepted

"Missed schedule" posting bug

You don't really need a Plugin to define these type of cronjobs in a timely manner. All you need to do is to reliably call the Wordpress Cron file which is wp-cron.php The question is if your Webhost ...
Helmi's user avatar
  • 118
3 votes
Accepted

wp_schedule_event run in background or not?

It depends. The initial page load trigger should not but performance may degrade as visitors browse your site until the Cron job is finished. Is the scheduled event you plan on using PHP or DB ...
cowgill's user avatar
  • 1,072
3 votes

Should I disable WP_CRON and trigger wp-cron.php from the server?

There are a couple of downsides: Firstly, when using wp-cron.php as a cli things such as $_SERVER variables aren't set. People overcome this limitation by using a curl request to wp-cron.php instead. ...
TechnicalChaos's user avatar
3 votes
Accepted

Avoiding "Missed Schedule" errors when inserting future posts

The missed schedule warning comes form those lines: https://github.com/WordPress/WordPress/blob/f884d7973b052c3efe0901bb136b9898ece8aa39/wp-admin/includes/class-wp-posts-list-table.php#L998,L999 It ...
david.binda's user avatar
  • 3,358
3 votes
Accepted

How to get woocommerce cart content without an action?

Not tested, but what if you use WC()->cart->get_cart() to retrieve the cart contents instead of the global $woocommerce object? However, I believe the problem is that cart contents require ...
Shawn H's user avatar
  • 681
3 votes
Accepted

Code does not work in class implementation but works fine in functions.php file

As Nathan has said in his comment above, the update_events() function needs to be a public function, not a private function: public scope to make that variable/function available from anywhere, other ...
Mat's user avatar
  • 1,627
3 votes

Safe to set permissions to 757 temporarily to update via wp-cli?

I think setting a cron job to automatically turn permissions on and off might be a bit of an extreme workround :-) I think it is probably worth spending the time to set up working permissions on your ...
junkrig's user avatar
  • 448
3 votes
Accepted

Wordpress function, Run using Crontab

define('DISABLE_WP_CRON', true); This line disables the default behaviour of WP Cron. Which is being triggered by a user that visits the site. This is bad for a couple of reasons (nobody might visit, ...
kero's user avatar
  • 6,200
3 votes
Accepted

How to Trigger WP CRON at Local Timestamp?

Part 1. The Time != The Timestamp This is your problem: every midnight at Local Timestamp There is no such thing as a local timestamp. Timestamps are not timezoned, it's not that WP uses UTC, but ...
Tom J Nowell's user avatar
  • 59.2k
3 votes
Accepted

Why is wp-cron only executing on page visit?

It's not possible with just WordPress to schedule code to run in the background at a specific time. WordPress, like most (if not all) PHP web applications, only actually runs in response to a URL ...
Jacob Peattie's user avatar
3 votes

How to force 'cron_schedules' every minute instead 1 hour?

You have the wrong period alias in your code You added your personal period in my_cron_schedules() as 61sec: $schedules["61sec"] = array( but use it in setup_schedule() as 61sek: ...
burlakvo's user avatar
2 votes

Running WP Cron on specific local time

First, make sure your WordPress date and time settings are correct as well as your local server time. Then use this code: $datetime = new DateTime('midnight', new DateTimeZone(get_option('...
Tyler's user avatar
  • 121

Only top scored, non community-wiki answers of a minimum length are eligible