WP Tuts Hub

WordPress Tutorials, Themes and Plugins Hub
Advertisement

Browse

  • Home
  • Categories
    • WordPress Troubleshooting
    • WordPress Tips and Tricks
    • SSH (Secure Shell)
    • WordPress Insights
    • WordPress Common Facts
    • Securing WordPress
  • Series Tutorials
    • Advanced WordPress Topic
  • Privacy Policy
  • Terms of Use
  • Contact Me
  • About WP Tuts Hub
Home/Advanced WordPress Topic/Using Cron Job in WordPress – Schedule Events With WP-Cron: Part 2
Advanced WordPress Topic
July 10, 2017

Using Cron Job in WordPress – Schedule Events With WP-Cron: Part 2

  • Using Cron Job
  • WordPress Cron Job
  • WP-Cron
WP Cron - All scheduled cron jobs

In the previous part of this series, we saw how to create schedule a cron, create a custom cron and unschedule it. If you missed it, I highly recommend reading that first as these two tutorials are connected. That was Using Cron Job in WordPress – Schedule Events With WP-Cron: Part 1

In this part of this Using Cron Job in WordPress series, we will see how to create an options page to show all cron jobs available in WordPress, all scheduled cron events and how to schedule a single event (instead of a recurring cron job).

Show all Cron events available in WordPress:

/**
 * Create an options page
 */
add_action('admin_menu', function() {
	add_options_page('WP Cron Settings', 'WP Cron Settings', 'manage_options', 'wptutshub-cron', function() {
		$cron = _get_cron_array();
		?>
			<div class="wrap">
				<h2>All Crons</h2>
				<?php 
					foreach ($cron as $time => $hook) {
						echo "<h3>$time</h3>";
						print_r($hook);
					}
				?>
			</div>
		<?php
	});
});

Cron Job in WordPress - See all cron events

Explanations:

Here I have registered an options page using add_options_page function which takes a good number of parameters. You can see more about this function at WordPress Codex (add_options_page). To get an array of all available cron events in WordPress, we have used a function named _get_cron_array. Anyway, this function is only for private use or only for our understanding.

Show all Scheduled Cron Events:

Now, we will enlist all of the scheduled cron events.

/**
 * Create an options page
 */
add_action('admin_menu', function() {
	add_options_page('WP Cron Settings', 'WP Cron Settings', 'manage_options', 'wptutshub-cron', function() {
		$schedules = wp_get_schedules();
		?>
			<div class="wrap">
				<h2>Scheduled Cron Events</h2>
				<pre><?php print_r($schedules); ?></pre>
			</div>
		<?php
	});
});

Show all scheduled cron jobs or events in WordPress

Explanations:

In this part, we have removed the previous _get_cron_array function and added a new function named wp_get_schedules which will return all scheduled cron jobs or events.

If we now want to make it a little bit readable by showing display name and interval aside, it will look like below:

/**
 * Create an options page
 */
add_action('admin_menu', function() {
	add_options_page('WP Cron Settings', 'WP Cron Settings', 'manage_options', 'wptutshub-cron', function() {
		$schedules = wp_get_schedules();
		?>
			<div class="wrap">
				<h2>Scheduled Cron Events</h2>
				<?php 
					foreach ($schedules as $name) {
						echo "<h3>". $name['display']. ': '. $name['interval']. "</h3>";
					}
				?>
			</div>
		<?php
	});
});

WP Cron - All scheduled cron jobs

Scheduling a Single Cron (instead of a recurring cron job):

You may find the necessity of scheduling a single event which will run only once instead of running repeatedly or recurrently, unlike a conventional cron job (like sending an email in 1 hour or make a query to a specific API). Well, in that case, you need to use wp_schedule_single_event() function which accepts three parameters (timestamps, hook and options arguments to pass to the hook functions.

Example:

wp_schedule_single_event( time() + 3600, 'wptutshub_cron_hook', array() );

I hope this article series has helped you to get started with WP-Cron event/job scheduling and how to use it in your plugin or themes. If you have any questions at all, feel free to comment below.

Share this:

  • Share on X (Opens in new window) X
  • Share on Facebook (Opens in new window) Facebook
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Reddit (Opens in new window) Reddit
  • Email a link to a friend (Opens in new window) Email

Related

Previous Article Using Cron Job in WordPress – Schedule Events With WP-Cron: Part 1
Next Article C Program to Store Multiple Student Records Using Array of Structures

About the author

Md. Zubaer Ahammed
Md. Zubaer Ahammed

Md. Zubaer Ahammed is a senior full-stack developer building learning platforms and modern web systems with WordPress, Laravel, Python/Django, Vue, and React. More at https://zubaer.com/.

Related Posts

  • Harden WordPress Application Passwords: Per-Role Availability, Revocation on Role Change and Auth Logging Harden WordPress Application Passwords: Per-Role Availability, Revocation on Role Change and Auth Logging
  • Build a Streaming WordPress AI Chat Assistant: SSE Endpoint, Conversation Table and Per-User Rate Limits Build a Streaming WordPress AI Chat Assistant: SSE Endpoint, Conversation Table and Per-User Rate Limits
WP Tuts Hub

WordPress tutorials, themes, and plugins — written for builders.

  • Portfolio
  • Calorie Calculator Pro
  • Contact
  • About
  • Privacy
  • Terms

© 2026 WP Tuts Hub · Md. Zubaer Ahammed

Loading Comments...