WordPress delete_get_calendar_cache() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Cache helper

Definition

In WordPress, delete_get_calendar_cache() removes the cached HTML that get_calendar() saved. The next time the calendar is shown, WordPress builds it again from the database.

WordPress already calls it for you when you save or delete a post. You call it yourself only when you change posts in a way WordPress cannot see, such as a direct database update.

Syntax

It takes no arguments and returns nothing.

WordPress
<?php
delete_get_calendar_cache();
CallWhat it does
delete_get_calendar_cache()Clears the saved calendar HTML.
add_action( 'save_post', 'delete_get_calendar_cache' )The hook WordPress already uses for you.
get_calendar()Builds a fresh calendar after the cache is cleared.

It only clears the cache. It does not print anything.

Full declaration
WordPress
delete_get_calendar_cache(): void

Parameters

ParameterDescription
NoneThis function takes no parameters.

Return Value

Return ValueDescription
voidNothing is returned.

WordPress Examples

Three short theme examples. Each one shows the code and what it prints.

Example 1 — Clear after a direct update

Refresh the calendar after you changed posts in the database.

WordPress
<?php
// ... bulk update posts with $wpdb ...
delete_get_calendar_cache();
echo 'Calendar cache cleared';

How It Works

  1. A direct database change does not fire save_post.
  2. We clear the cache ourselves.
  3. The next get_calendar() shows the new post dates.

Example 2 — Run it on your own hook

Clear the cache when your plugin finishes an import.

WordPress
<?php
add_action( 'my_import_done', 'delete_get_calendar_cache' );

// later, when the import ends:
do_action( 'my_import_done' );

How It Works

  1. add_action() connects our event to the function.
  2. do_action() runs it.
  3. No output is printed because the function returns nothing.

Example 3 — Clear then rebuild

Show the calendar again after clearing.

WordPress
<?php
delete_get_calendar_cache();
get_calendar();

How It Works

  1. The old cached HTML is removed.
  2. get_calendar() reads the posts again.
  3. The new table is printed with up-to-date links.

Frequently Asked Questions

It removes the saved calendar HTML from the object cache so get_calendar() builds it again.
No. WordPress calls it automatically on save_post and delete_post.
No. It returns nothing (void).
Call it after you change post dates or statuses in a way that skips the normal save hooks, such as direct SQL or a custom import.

Next: get_archives_link()

Build one archive link as a string in html, option, link, or custom format.

get_archives_link() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful