Whenever I change the time intervals for ex: from ‘three_days’ to ‘five_minutes’ or from ‘five_minutes’ to ‘fifteen_minutes’, the cron is running with earlier frequency and not the updated one.
Because you only reschedule the event if it does not exist:
if ( ! wp_next_scheduled( 'bd_cron_cache' ) ) {
// schedule
}
…which will always be false once you initially schedule the event. Instead, check the stored task’s schedule against the value you actually want it to be:
if ( wp_get_schedule( 'bd_cron_cache' ) !== 'twenty_minutes' ) {
// Above statement will also be true if NO schedule exists, so here we check and unschedule if required
if ( $time = wp_next_schedule( 'bd_cron_cache' ) ) {
wp_unschedule_event( $time, 'bd_cron_cache' );
}
wp_schedule_event( time(), 'bd_cron_cache', 'twenty_minutes' );
}
Related Posts:
- Running WP Cron on multisite the right way
- Initialize WordPress environment to use in a real cron script
- Multiple wp_schedule_event cron jobs in plugin cause multi-execution
- Does wp-cron runs all tasks scheduled at same time together or one after other?
- export a csv file from the database with a cronjob
- How wp-cron can run in background if PHP is single threaded?
- WP Cron job timeout issues
- running wp-cron.php using php not wget
- Large WordPress CRON job
- How to Schedule Cronjobs for start of every month and year
- Can/should we delete wordpress cron jobs with no action?
- Setting up a cron job to auto update a custom field
- CRON job to update wp_usermeta value each day or week based on server time
- Cron not sending wp-mail()
- Php cron job (wp-cron) not working
- Execute scheduled cron with ajax call to wp-cron.php
- Running WP-Cron on Multisite networks the right way?
- How can I cause run wp-cron to trigger sequentially?
- Converting timestamps to local time with date_l18n()
- Uncaught Error: Call to undefined function wp_generate_attachment_metadata() @ wp-cron
- wp_delete_auto_drafts() deletes links in menus
- How to run multiple Async HTTP requests in WordPress?
- What would be a PHP command to erase all posts from category X from the last month?
- How to correct schedule my event weekly with wp_schedule_event()
- How to make sure that only one wp_cron() runs at a time?
- Run W3 Total Cache Flush Function with Crontab [closed]
- wp_delete_auto_drafts() deletes links in menus
- How to start a script from cli within wordpress
- How to get woocommerce cart content without an action?
- WP_cron won’t trigger my action
- Cron events are disappearing, or cannot be updated in WordPress
- How to bypass maintenance mode with external cron?
- WP CRON duplicate wp_insert_post with has < and > tag
- Best way to schedule daily change in CSS parameter
- Scheduling an event inside plugin class is not working
- Switch from wp-cron to a server cron job
- Unzip file in functions.php, and add it to cron
- Wp_Schedule_Event every few minutes doesn’t work
- Multiple cron jobs vs daily cron job doing multiple things? Which one yields better performance and scalability?
- post_exists stops working in a scheduled event
- Automatically delete posts one by one depending on published time
- Use WP Cron to Clear a Page Cache?
- New database entry to trigger runing PHP/SQL query through link with token, without logging into the website
- Update all posts in custom post types with wp_cron()?
- Sort WooCommerce data with WP-CRON?
- How do I routinely extract the thumbnail of the most recent post?
- Break a WordPress function to run in patches and re-continue
- WPMU schedule doesn’t execute actions
- Cron job to call php to email last 24 hours posts
- How does one programmatically manage posts from a external php script?
- How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
- How to avoid timeout waiting for output from CGI script?
- wordpress.org disallowing my plugin becuase of loading core files in cron cpanel file
- understanding wp_next_scheduled
- Error resetting database index using ALTER TABLE in $wpdb->query
- Background Tasks in a WP Cronjob?
- Generate random number 1-10 upon registration without repeat
- Start a long running PHP process via JS/Ajax and monitor progress on admin page
- How exactly do automatic updates work?
- How to create custom 401, 403 and 500 error pages?
- Why have on every line
- add_action in namespace not working
- Is it possible to disable a function of a parent theme?
- Variables declared in header not available in other includes
- Hide old attachments from wp media library
- WordPress Ajax always returns a 404 error
- Displaying a variable stored in functions.php inside widget
- Custom Meta Field – Youtube embed
- Failed to open stream / no such file or directory
- Need to get specific data from array
- Use different javascript files for each page on website
- How to get all existing post types
- WooCommerce – Fixed quantity of a product [closed]
- How to create post thumbnail
- Settings API – sanitize_callback is not called and it leads to an incorrect behavior
- phpMyAdmin displays error when importing database
- Setting up 2 SMTP accounts: 1 for wordpress and 1 for woocommerce
- Function set default image when image not present
- How to get the POST TITLE using the POST ID?
- Importing hard coded custom field into acf field
- Adding country tags automatically
- Displaying the last post on static homepage
- Using foreach loop breaks
- Add child pages of parent to navbar PHP
- From where the header-text can be changed in WordPress custom header?
- Trying to establish connection to External Database
- Load a page into a div with Ajax
- Showing a different gallery in a seperate post
- Login/logout in header
- How to put “Read more” link in Custom Excerpt inside p tag?
- $wpdb->update with multiple parameters gives error
- loop through meta_query relations [closed]
- Improve page speed loading using CDN and async or defer attribute
- Applying A Category to Existing Posts Where Page Title Matches Regex
- Dashboard broken into list of links
- Get users that likes the post
- wordpress visual composer change grid builder post link
- System Cron job not firing
- PHP array to JS array to use in google map
- Displaying recent posts on static page with template-part via shortcode