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
- 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?
- How can I send an email using PHP?
- List of all theme customizer control types?
- Load post content into iframe
- WordPress widget in custom theme
- Specific Loop For 2 Within Each
- POSTS list in WordPress by views
- Anything I can add to functions.php to make text widgets accept PHP?
- What’s the proper way to use wp_enqueue_script/style?
- Can’t increase posts_per_page by variable
- How to check If Oembed is empty or not
- How do I access the media settings
- How can I output a php value into a JS file within WordPress?
- Set post title based on first h2 element in the content section
- Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?
- Show css depending on activity type in BuddyPress activity-loop [closed]
- Settings API callback function inserts html quotes from nowhere
- Show when user is online/offline in real time on user_profile.php
- Call to undefined function get_userdata() in plugin
- How to add different text in each result of foreach?
- multiple where condition in result query
- Featured or last post with a different WordPress style without plugin
- Writing PHP code in pages without issue?
- How to get User Time Zone in WordPress?
- Fix error Gravatar alt
- WordPress yoast seo plugin – parse snippet var in meta description
- Different SMTP based on domain
- How to edit the styles for the table of pages/post listed in the admin when you click on pages/posts?
- get different meta-data of a complicated query at the same time
- Get only relevant sub-category of category “Genre” that applies to current product only
- How to escape echo for input tag?
- Warning: count(): syntax problem of the count () function
- Reload page with a different shortcode when a user selects from a dropdown
- WooCommerce get products based on the taxonomy
- Woocommerce Add custom “Add to cart button” in single page with tags
- Displaying child taxonomy before parent
- Better way to run heavy scripts using WordPress database
- Update same content in multiple posts at once?
- Different home page for logged off users
- Send data from plugin to external database
- WP Admin Bar – Get current theme name as custom menu title
- Show custom default avatar instead of gravatar
- the_post_thumbnail unless video id is added
- New to WordPress & Freelancing [closed]
- Add a “Next Post” & “Previous Post” styled button manually to a post
- How to store the_post_thumbnail() value in a variable
- Can’t insert into a database wordpress
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress