Auto refresh WordPress posts older than set days: setup and test
By Sophie Adams Published 10 min read
On this page (8 sections)
- Key takeaways
- What you need to auto refresh aging WordPress posts
- How to detect post age in WordPress
- Code or plugin methods to trigger auto refresh
- How to set the refresh interval based on post age
- How to verify auto refresh is working
- Common mistakes when auto refreshing WordPress posts
- Questions people still ask
In short: To auto refresh WordPress posts older than a set number of days, detect post age using their publish date, apply a scheduled task to update only posts older than that threshold, and verify by checking post modified dates after refresh. Plugins like Ama Affiliate Ultra automate this process.
Part of our guide on convertkit emails in spam folder
This guide shows how to automatically refresh only WordPress posts older than your chosen age, with setup and verification to keep content fresh.
| Post age trigger | Set by user (e.g. 30 days) |
|---|---|
| WP-Cron interval | Hourly or daily |
| Post modified update | Timestamp changes |
| Plugin option | Ama Affiliate Ultra |
| Verification method | Check modified date |
| Manual code skill | Intermediate PHP |
Key takeaways
- Detect post age by comparing publish date to current date in WordPress queries.
- Use scheduled events to trigger refreshes only on posts older than your chosen age.
- Plugins like Ama Affiliate Ultra handle automated refreshing and analytics easily.
- Verify refresh by checking the post's last modified timestamp updates after refresh.
- Manual code methods require custom WP-Cron scheduling and post query filtering.
What you need to auto refresh aging WordPress posts
You need basic WordPress admin access to install plugins or add code snippets safely.
A plugin or ability to add PHP code to your theme’s functions.php or a site-specific plugin.
A way to check post dates, such as access to the WordPress admin Posts list or database query tools.
Optionally, a tool like Ama Affiliate Ultra to automate and manage refreshing large affiliate sites. People in this spot often ask about creating niche printable products as well.
For sites with high traffic or numerous posts, it’s important to consider server resources before implementing auto refresh. Frequent refreshes, especially on many posts, can increase CPU and database loads. Testing on a staging environment first can help identify any performance bottlenecks.
If you prefer not to use plugins, setting up a child theme for your code snippets prevents losing customizations during theme updates. This way, your auto refresh code remains intact and avoids conflicts with theme changes.
- WordPress site with admin access
- Plugin installation capability or code editing access
- Knowledge or tools to read post publish and modified dates
- Optional: Ama Affiliate Ultra plugin for automation
How to detect post age in WordPress
Post age is the difference between the current date and the post’s publish date stored in the post_date field. If that sounds like your situation, read up on how to automate planning and scheduling affiliate posts next.
Use WordPress functions like get_the_date() or custom database queries to filter posts older than your target threshold in days.
For example, to find posts older than 30 days, compare post_date against the current date minus 30 days using PHP’s DateTime or SQL queries.
The post_modified field shows when a post was last updated, which helps verify if the refresh worked. If that sounds like your situation, read up on how to plan affiliate content for amazon site next.
Post age can also be affected by timezone settings in WordPress and the server. Ensure your site’s timezone matches your target audience’s to accurately measure post age; otherwise, posts could appear older or newer than intended.
For example, if a post was published on March 1st at 3 PM and your server time is in UTC, but your site timezone is UTC+2, the post age calculation will differ by two hours. Adjusting for this ensures precise filtering.
A practical check: retrieve a post’s publish date with get_the_date('Y-m-d H:i:s', $post_id) and compare it to the current date/time in the same timezone using PHP’s DateTime class. This confirms your detection logic before applying updates. It helps to understand how to run seo audit on affiliate site quickly before going further.
- Access WordPress admin and navigate to Posts > All Posts.
- Sort posts by publish date to identify those older than your refresh threshold.
- Alternatively, use a SQL query like
SELECT ID FROM wp_posts WHERE post_date < DATE_SUB(NOW(), INTERVAL 30 DAY). - Record or note posts older than the chosen number of days.
Code or plugin methods to trigger auto refresh
You can refresh posts automatically using either scheduled code (WP-Cron) or a plugin that handles updates.
WP-Cron allows scheduling a custom task that queries posts older than your set days and programmatically updates them.
Updating includes modifying the post content or simply changing the 'last modified' timestamp by calling wp_update_post(). The other half of this decision is mailerlite automation sequence for product launch.
Ama Affiliate Ultra plugin offers an automated method to refresh aging posts without manual coding, specifically designed for affiliate sites.
Manual code requires intermediate PHP skill and testing to avoid performance issues or accidental mass updates.
When using WP-Cron for scheduled refreshes, keep in mind that WP-Cron depends on site traffic to trigger. On low-traffic sites, scheduled tasks might not run exactly on time. To avoid this, consider setting up a real server cron job to call wp-cron.php at fixed intervals. We cover how to create a lead magnet pdf fast in its own article.
A simple example of updating a post’s modified date without changing content is calling wp_update_post(['ID' => $post_id]). This triggers WordPress to update the modification timestamp, which some plugins and search engines interpret as fresh content.
For plugin methods, ensure the plugin supports selective refreshing. Some plugins refresh all posts indiscriminately, which can degrade SEO and server performance. Ama Affiliate Ultra specifically targets posts older than your set threshold, improving efficiency.
| Method | Ease of Setup | Control Level | Automation | Risk |
|---|---|---|---|---|
| Manual Code | Medium to High | High | Requires manual scheduling setup | Potential for errors without testing |
| Ama Affiliate Ultra Plugin | Low | Medium | Full automation with AI content options | Limited to affiliate use cases |
- Manual code allows full control
- Plugin automates schedule and content update
- Plugin integrates analytics
- Manual code is free
- Manual code requires PHP knowledge
- Plugin limited to Amazon affiliate sites
- Manual code needs testing to avoid errors
- Plugin cost and dependency on AI API
How to set the refresh interval based on post age
Choose a refresh interval by deciding how old posts must be before refreshing, e.g., 30, 60, or 90 days.
In code, this means filtering posts where post_date is older than current_date - interval.
WP-Cron jobs can run hourly or daily; the interval choice affects how often the refresh task triggers.
Ama Affiliate Ultra lets you set the refresh age in its settings, handling the scheduling and selection automatically.
A shorter interval means more frequent refreshing but potentially more server load; longer intervals risk posts becoming outdated.
If your site includes different categories or post types, consider applying different refresh intervals per category or type. For example, news posts may need refreshing every 7 days, while evergreen content might only require refreshes every 90 days.
You can achieve this by extending your code’s filtering logic to include taxonomies or post type checks along with the post_date threshold. This segmentation helps optimize resources and maintain content relevance.
Monitoring is key: track how often posts are refreshed and whether traffic or engagement improves. Adjust your intervals accordingly to balance freshness with server load.
- Decide the maximum post age before refresh (e.g., 30 days).
- In code, write a query to get posts where
post_date<now - 30 days. - Set up a WP-Cron event to run daily or hourly depending on how often you want to check.
- For the plugin, access the settings and specify the refresh interval in days.
- Monitor server load and adjust interval if refresh tasks cause performance issues.
How to verify auto refresh is working
Verification is essential: check that the post_modified date changes when a post is refreshed.
In WordPress admin, enable the 'Last Modified' column or use plugins that show this data.
You can also query directly on the database to see if post_modified is updated after scheduled refresh.
Ama Affiliate Ultra provides a report showing which posts were refreshed and when, simplifying verification.
If timestamps do not update, your scheduled task may not be running or the update code may not execute correctly.
Besides checking the post_modified date, you can verify successful refresh by adding debug logging in your code. For instance, log post IDs updated along with timestamps to a custom log file to audit refresh activities.
Additionally, browser developer tools can help confirm scheduled tasks run correctly by inspecting AJAX calls or REST API requests if your refresh method triggers via these mechanisms.
If the post_modified date updates but you don’t see content changes on the frontend, ensure caching plugins or CDNs are cleared or configured to respect content updates. Otherwise, stale content may persist despite backend refreshes.
- Before refresh, record the
post_modifieddate of a few older posts. - Trigger or wait for the scheduled refresh to run.
- Afterward, check the same posts’
post_modifieddates to confirm updates. - Use WordPress plugins like 'Simple History' to monitor scheduled tasks.
- Review plugin logs if using Ama Affiliate Ultra.
Common mistakes when auto refreshing WordPress posts
Another common mistake is failing to back up the site before enabling auto refresh. Updates that modify posts programmatically can cause unintended content changes or data corruption if bugs exist in the code or plugin.
Also, some users set the refresh interval too short, such as every day, causing excessive server load and potential hosting limits being hit. Generally, intervals shorter than 7 days are not recommended unless posts require daily updates.
Make sure permissions are correctly set; insufficient user capabilities or read-only database access can cause update failures without obvious errors. Testing the refresh process on a staging site first helps identify such issues.
- Over-refreshing – Setting too short an interval causes server strain; use 30-60 days usually.
- No verification – Not checking post modified timestamps leads to false assumptions about refresh success.
- Wrong post filter – Refreshing all posts instead of just those older than set days wastes resources.
- Lack of backup – Running refresh without backups risks data loss if code malfunctions.
- Ignoring plugin limits – Using generic plugins that don’t support selective refreshing causes mass updates.
Questions people still ask
Can I auto refresh posts without a plugin?
Yes, by adding custom PHP code that uses WP-Cron to schedule post updates filtering by post age, but you need intermediate coding skills and careful testing.
Does auto refreshing posts affect SEO?
Refreshing content can improve SEO by signaling fresh content, but excessive updates without meaningful changes might not help and could confuse search engines.
How often should I refresh aging posts?
Typically, every 30 to 60 days is good; it depends on your niche and how quickly content becomes outdated.
What does Ama Affiliate Ultra do for refreshing posts?
It automates detecting and updating older posts using AI-generated content and schedules refreshes based on your settings, plus provides analytics.
Can I set different refresh intervals for different posts?
Custom code can handle complex rules but plugins usually apply a global interval; Ama Affiliate Ultra may allow some customization.
Ready to try it? It automates detecting and refreshing aging posts, saving time and ensuring your affiliate content stays current.
Try Ama Affiliate Ultra free