Toolsnip

Wordpress: Automatically Archive Old Posts

Keep your WordPress site organized and up-to-date by automatically archiving older posts with this handy snippet.

Keeping your site's content fresh and relevant is important, and archiving old posts can help. This snippet automatically archives posts that have not been updated or viewed within a specified time frame.

Scheduled using the 'wp_cron' function, this script checks posts based on their last modified date and views, archiving those that meet the criteria.

Configuration options for setting the time frame, such as archiving posts older than a year, are provided, along with methods for customizing the archival process.

The snippet also explains how to handle archived posts, such as removing them from regular search results or moving them to a specific archive page.

Best practices for notifying users about archived content and options for restoring or permanently deleting posts are also included.

Snippet Code

Version Compatibility

This snippet is effective with WordPress 3.0 and later, utilizing WP-Cron for scheduled tasks.

Required PHP Version

PHP 5.4 or higher

Wordpress Core Functions Used

Use Cases

  • content management
  • site maintenance
  • archive functionality