Cron Job

Cron Job

“Cron Job is a time-based job scheduler.” It is a system that enables users to implement commands, programs, and other actions at a particular time.

Basically in an era where a customer has a lot of options to choose from, it becomes necessary that a brand keeps up with its presence, Hence, the recalling feature should definitely be on your priority list.

Why Cron job?

Cron Job is a system that schedules an action to take place at a specific time in the future without actually having someone to perform it. Hence, it runs on an automated form.

In order to automate, Word press uses a file known as wp-cron.php as a virtual cron job, for performing tasks:

  • That occur at regular intervals.
  • That occur once at a fixed time.

Examples of tasks occur at regular intervals:

  • Website Backup.
  • Ensuring WordPress is in it’s latest version.
  • Ensuring plugins and themes are up to date.
  • Database optimization for performance improvement.

Examples of tasks occurring at a fixed time.

  • Posting a blog post at a particular time.
  • Email outburst at a specific time.

The WordPress cron system without code can be configured and operated. Let us explore how!

The first thing we need to do is install and activate the WP Control plugin.

  • Log in to the Admin Panel.
  • Go to WP Admin >> Plugins >> Add new. Find for WP Control or directly download from here.
    Wp Event Manager Cron Job 1
  • Install the plugin.
  • After the plugin is installed and activated, Go to the Installed plugin menu and search for the WP control plugin and click on Cron Event.
    Wp Event Manager Cron Job 2
  • Find your scheduled actions in the Cron events section of the tools list.
    Wp Event Manager Cron Job 3

Adding Cron Events in WordPress

In order to add cron jobs to WordPress one needs to go to Tools » Cron Events page and scroll down to the ‘Add Cron Event’ tab.

You can now customize your own cron event in WordPress:

  • Add a hook name to your cron event.
  • Provide arguments, if the function you want to execute requires it.
  • Then  inform WordPress about when to run the cron next time. You can enter ‘now’, ‘tomorrow’, ‘+4 days’, or a specific date, ’25-02-2020 12:34:00′.
  • Lastly, select the schedule. It may be hourly, thrice daily, daily, or once a week. You can also make it a non-repeating event.
  • Next, save the changes by clicking on the Add Cron Event button.
  • The cron event will now appear in the events schedule list.
  • However, the task does not end here as we haven’t told WordPress what to do when this event is triggered.
  • Therefore, add your hook and function that runs when the cron hook is triggered.
  1. add_action( 'wpb_custom_cron', 'wpb_custom_cron_func' );
  2.   function wpb_custom_cron_func() {
  3.   wp_mail( 'you@example.com', 'Automatic email', 'Automatic scheduled email from WordPress to test cron');
  4.   }
  • Test the function now!
    • Related Articles

    • How to delete an expired event by time

      In Order to display an event as Expired after a specific date and time, you need to add the following code to your theme functions.php file. Open your child theme, Add the code into the funtions.php file. /* Event Expire by time */ function ...
    • Importing Event Listings With WP All Import Pro

      WP All Import Pro allows you to import posts and custom post categories (like occasional postings) with CSV and XML documents. Steps for importing from a CSV file are given below. Preparing Your CSV File Event Title. Event Description. Event ...