This code will call your function every hour.
// The 'if' condition is needed to make sure the scheduler runs only once
if ( ! wp_next_scheduled( 'my_custom_action' ) ){
wp_schedule_event( time(), 'hourly', 'my_custom_action' );
}
// Here we create our own action to attach to the scheduler
add_action( 'my_custom_action', 'update_content' );
It is also recommended you clear all scheduled events when you deactivate the plugin like so:
// The deactivation hook is executed when the plugin is deactivated
register_deactivation_hook( __FILE__, 'my_deactivation' );
function my_deactivation() {
wp_clear_scheduled_hook( 'my_custom_action' );
}
Note that if your website has zero visitors the cron will not run, image taken from here:
You can read more about wp_schedule_event()
here.
Related Posts:
- How ( and mostly at what time ) can i prevent the alternate cron from running?
- How does task scheduler plugin implements cron that is not dependent on page load request? [closed]
- Switch from wp-cron to a server cron job
- WordPress cron job running more than once
- Activate Plugin Automatically After Set Time
- Better way to run heavy scripts using WordPress database
- WordPress Cron function is not working
- Adding custom cron_schedule prior to wp_schedule_event
- Uncaught Error: Call to undefined function wp_generate_attachment_metadata() @ wp-cron
- Schedule WordPress Auto-Updates to only run during business hours
- How do I email a new page password to somebody every month?
- What happens when wp_cron is deactivated in WordPress?
- wp_schedule_single_event function not working
- action-scheduler vs wp-background-processing
- Why is wp-cron only executing on page visit?
- How to periodically scrape and cache strings from remote txt files. – My First Plugin
- Does using WP-cron make the site slower for the user?
- wp_schedule_single_event not working: cron job is triggered but nothing gets executed
- How to make a implement queue for scheduling tasks in WordPress?
- Setup wp_schedule_event within a custom plugin
- How to set intervals in cron jobs?
- What causes wp_schedule_single_event to fire off?
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- Cron task gets removed from the schedule
- WP_CRON issue with UTC and local time
- WordPress crob job performance
- How to customize ‘recurrance’ of’ wp_schedule_event’?
- How to set-up multiple cron task with wp_schedule_event so that they do not overlap?
- Running a function using Crown WordPress on one day a week, for example, Mondays of every week
- Update plugin from personal API
- Does a plugin’s “main” file need to be named the same as the folder containing it?
- Symlinked plugin directory doesn’t appear in Admin
- enqueue script only if it is not already enqueue
- How can I limit functionality in one version of a plugin?
- Cron Job not working in plugin
- Plugin child folder?
- Custom data-id wp_enqueue_script
- How use %like% in sql statement wordpress
- Can I use a form in a dashboard widget?
- Retrieving plugin options value saved through setting
- How to ‘clone’ a wp plugin to make small changes
- MITM risk of not sanitizing?
- Get IDs of Images from Gallery Block in InnerBlocks of a Custom Gutenberg Block
- How to slice an array using posts_per_page? [closed]
- Edit Yoast SEO breadcrumbs output [closed]
- Enqueue WordPress plugin scripts below all other JS
- White page by using filter template_include
- Is there any kind of theme on WordPress to sell my own movies?
- User switching only with specific role and return
- Automatic plugin updates not working
- Fromcraft Plugin On click submit button [closed]
- Suggestions on Approach to New Plugin I’m Stuck On
- How to redirect users to their profile after they successfully edit their profile
- WordPress error: Options page Setting_ not found in the allowed options list
- What is wordpress way to access a plugin’s classes/models to load custom post type data?
- flush_rewrite_rules() not working with update_option_{$option}
- plugin wraps the entire content
- How to ignore extra whitespaces in translation functions like _e?
- How does translation (gettext) work for translating config file of plugin?
- How programatically cause uploads folder to be created?
- The “Child Pages Shortcode” plugin, block template
- using wp_footer hook in a plugin
- How to get a custom page through plugin?
- I’m looking for a plugin to execute a specific task a certain time
- Want to create custom design of progress indicator in wpforms
- Using Class loader in WordPress boilerplate
- How to prepare (compress/zip) a plugin to enable updating instead of adding new instance?
- WC Fix Attributes – ‘Add New’ Not Searchable/Delayed
- Custom plugin activation error
- The Build menu theme is frozen with the wordpress theme
- How to capture hidden values with Gravity Forms
- How to translate to spanish wordpress hardcoded content/files?
- what functions to use to resize images and create DB metadata for them after/during upload?
- Multiple image selection custom widget
- How to Create a Learning Management Plugin in WordPress to Manage Courses [LMS]
- How to prevent redoing get_posts queries and make results available to other scripts?
- Paid Membership Pro displaying a user name in PHP
- Make another copy of a plugin and install it
- Store admin page into variable
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- WP Plugin CSS not being applied to page
- Overwriting Plugin’s Ajax callback function from theme
- How can I get the Post ID and Post Type within a Must Use Plugin?
- Creating Nested custom fields
- Unable to sync woocommerce variations
- Can’t find variable is_single in my jQuery plugin
- Plugin hook breaks new WP 4.0 media library grid view?
- How to get site homepage from plugin?
- Get page type to display content
- Widget redirecting to home page
- Is an Office a custom post type [closed]
- How to add image for custom taxonomy
- I am using multi image metabox plugin but I did get how to display the images in templete?
- WordPress Hooks : Where to place callbacks that repetitively yield the same effect?
- wordpress Ajax success doesn’t return the value
- How to open author url linked to a new tab in settings page in the WordPress plugin list
- How can I properly sanitize the update_option in WordPress?
- Why is my menu page not being displayed?
- Function not being called on form submit, only blank admin-post.php page
- How to give specific class name to category in wordpress with code snippets