By default, Aggregator never removes an imported item just because it is missing from the current feed. Fetching a source adds new items and updates existing ones, but items that have dropped out of the feed stay on your site. This is the safer default, because many feeds only expose their newest items. An older item missing from the feed does not mean it was deleted at the source.
This is also the case when the Keep items up-to-date option is enabled. That option updates the content of imported items that are still in the feed, but it does not remove items that are no longer there.
In some cases, you may want your site to mirror the source feed exactly. For example, if you import job listings, you may want a listing that was removed from the source feed to disappear from your site after the next fetch.
Aggregator includes a developer filter that allows you to opt in to this strict sync behavior, per source or site-wide.
When to Use This
Use this approach when:
- You use a source to mirror an upstream feed, such as job listings or event calendars.
- Items removed from the source feed should also be removed from your site.
- The feed always contains the complete list of current items, not just the newest ones.
Do not enable strict sync for feeds that only show their most recent items, such as typical blog or news feeds. On every fetch, strict sync removes the source’s previously imported items and re-imports only what is in the feed right now, so older imported items would be permanently removed.
Add the Snippet
To enable strict sync for a single source, add this snippet to your site, replacing 123 with the source’s ID:
add_filter(
'wpra.importer.source.strict_sync',
function ( $enabled, $source, $num, $page, $pid ) {
return isset( $source->id ) && (int) $source->id === 123;
},
10,
5
);
To enable it for all sources on the site:
add_filter( 'wpra.importer.source.strict_sync', '__return_true' );
After adding the snippet, the next full fetch of the source will remove its previously imported items and import the current feed items again. From then on, items that disappear from the feed will also disappear from your site after the next fetch.
Note: If you are unsure how to add the code snippet to your site, see Adding Custom Actions and Filters.
Important Note
- Removed items are deleted permanently, not moved to the Trash. Only enable strict sync when the current feed is the complete list of items you want on your site.
- Strict sync runs only on full fetches, such as scheduled updates. Imports with a limit and paginated imports do not trigger it.
- Strict sync runs only after the feed has been read successfully. If a fetch fails, nothing is removed.
- Posts protected by the Do Not Delete Edited Posts option are not removed by strict sync.
- Your source’s import limit and item age limit settings are separate and continue to work as before.
If Items Are Not Being Removed
Check the following:
- Make sure the snippet is active on your site, and that the source ID in the snippet matches the source you want to sync.
- Confirm the item is actually missing from the current feed content.
- Wait for, or trigger, a full fetch of the source. Limited or paginated imports do not run strict sync.
- Make sure your site is using Aggregator version 5.3.0 or later. The
wpra.importer.source.strict_syncfilter was added in version 5.3.0.
Can I Use This for Large Sources?
Yes. When strict sync runs, existing imported items are removed in batches of 500, so sources with many imported items are handled safely. The removal and re-import happen within the same fetch, so the source’s items are briefly unavailable while the fetch completes.